【发布时间】:2014-09-24 01:06:15
【问题描述】:
我正在尝试增加条形图上日期的 xtick 和标签频率。它目前每 2 个月放置一次标签,我想将其增加到每个月。
我目前的代码是:
fig = plt.figure()
ax = plt.subplot(1,1,1)
# defining the spacing around the plots
plt.subplots_adjust(left = 0.125, bottom = 0.1, right = 0.9, top = 0.9, wspace = 0.2, hspace = 0.35)
handles = [] # for bar plot
bar1 = ax.bar(dates, clim[loc,:], label = 'climatology (1981 - 2013)', color='darkgray', width=width_arr[:], linewidth=0, alpha=0.5)
handles.append(bar1)
bar2 = ax.bar(dates, chirps[i,loc,:], label = str(year1), color = 'blue', width=width_arr[:], linewidth=0, alpha=0.45)
handles.append(bar2)
# setting the plot tick labels
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(10)
for tick in ax.yaxis.get_major_ticks():
tick.label.set_fontsize(10)
ax.set_ylabel("Precipitation", fontsize=10)
# plotting the legend within the plot space
plt.legend( loc = 'upper left', numpoints=1, ncol = 3, prop={'size':10})
plt.ylim(0, 110)
# rotating the tick marks to make best use of the x-axis space
plt.xticks(rotation = '25')
【问题讨论】:
-
您提供的代码没有太大帮助,因为我们不知道
dates或clim是什么样的。尝试添加一个显示您所拥有的最小工作示例,不要包含不相关的plt.subplots_adjust之类的内容。这将提高答案的质量/数量。
标签: python date matplotlib plot bar-chart