换档直方图X轴杆的开始和结束(从7月到6月)
我想更改直方图的开始和结束月的开始和结束月,以便看到酒吧如下:11月,12月,1月,2月3月。
这个想法是从第7个月开始开始的hist.lot。以6结束(例如)。
我的代码是这样的:
d = {'days': [7 , 33 , 50 , 51 , 53 , 71 , 84 , 85 ,324 ,343 ,344 ,345 ,357],
'month': [ 1, 2, 2, 2, 2, 3, 3, 3,11,12,12,12,12]}
df_example = pd.DataFrame(data=d)
然后我正在使用的函数:
def histogram_ssw(variable1, variable2, title):
fig, ax = plt.subplots(1,1,figsize=(20,7))
fig.suptitle('Histogram' + title,fontsize=22,weight='bold')
mean = variable2.mean()
std = variable2.std()
count1,bins1,ignored1 = ax.hist(variable1[~np.isnan(variable1)],bins=25,density='True')#,label='empirica')
ax.set_title('whatever');
ax.set_xlabel('days')
ax.set_ylabel('frec')
ylim0 = ax.get_ylim()
x1 = np.linspace(bins1.min(),bins1.max(),100)
N = nor(np.nanmean(variable2),variable2.std(),x1)
x_formatter = dates.DateFormatter('%m-%d')
#ax.xaxis.set_major_formatter(x_formatter)
ax.xaxis.set_major_locator(dates.DayLocator(interval=1))
plt.gcf().autofmt_xdate(rotation=60)
#ax.set_xticklabels(df_niño3EP["M-D"].tolist(),rotation = 60)
#ax.tick_params(axis="both", direction="in", pad=15)
#ax.get_xticks(df_niño3EP["M-D"])
#mmax = np.max(ylim0[1])
#ax.set_ylim([0,mmax])
ax.grid()
plt.show()
我们执行DF的函数:
histogram_ex(df_example['months'], df_ejemplo['days'], 'pff')
返回:
您可以看到它们是分开的,我希望它以中心为中心...
I would like to change the start and end month on my histogram so I can see the bars followed: November, December, January, February an March.
The idea is start the hist.plot from month 7 and end in 6 (for example).
My code is something like this:
d = {'days': [7 , 33 , 50 , 51 , 53 , 71 , 84 , 85 ,324 ,343 ,344 ,345 ,357],
'month': [ 1, 2, 2, 2, 2, 3, 3, 3,11,12,12,12,12]}
df_example = pd.DataFrame(data=d)
Then the function I'm using:
def histogram_ssw(variable1, variable2, title):
fig, ax = plt.subplots(1,1,figsize=(20,7))
fig.suptitle('Histogram' + title,fontsize=22,weight='bold')
mean = variable2.mean()
std = variable2.std()
count1,bins1,ignored1 = ax.hist(variable1[~np.isnan(variable1)],bins=25,density='True')#,label='empirica')
ax.set_title('whatever');
ax.set_xlabel('days')
ax.set_ylabel('frec')
ylim0 = ax.get_ylim()
x1 = np.linspace(bins1.min(),bins1.max(),100)
N = nor(np.nanmean(variable2),variable2.std(),x1)
x_formatter = dates.DateFormatter('%m-%d')
#ax.xaxis.set_major_formatter(x_formatter)
ax.xaxis.set_major_locator(dates.DayLocator(interval=1))
plt.gcf().autofmt_xdate(rotation=60)
#ax.set_xticklabels(df_niño3EP["M-D"].tolist(),rotation = 60)
#ax.tick_params(axis="both", direction="in", pad=15)
#ax.get_xticks(df_niño3EP["M-D"])
#mmax = np.max(ylim0[1])
#ax.set_ylim([0,mmax])
ax.grid()
plt.show()
We execute the function for my df:
histogram_ex(df_example['months'], df_ejemplo['days'], 'pff')
So it returns:
As you can see they're separated and I want it centered...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此处
,我将附加属性
底部
添加到您的ax.hist()
构造函数中。我没有尝试过,所以LMK,但是可以找到更多在这里 (文档)
try this
where i added an additional property
bottom
to yourax.hist()
constructor.i haven't tried it so lmk but more can be found here (docs)