我正在基于底层数据动态创建多个子图。 x轴是日期时间,每个子图的小时数不同。当我设置最终轴主要定位器时,它会影响所有轴的所有定位器。例如,如果最终子图时间范围是00:00到06:00,第一个子图范围是00:00到13:00,则maplotlib只在第一个子图上放置标签,范围从00:00到06:00。 / p>
如果我让它自动定位,它会放置足够数量的标签,但时间间隔会有所不同。它可能会在06:28打勾,当时我希望滴答在一小时内落下。
以下是代码段:
fig = plt.figure(figsize=(fw, fh))
plt.suptitle(title, horizontalalignment = 'left', x= 0.12, y=0.955, fontsize = 14, name = 'Arial')
f = '#4C709D'
m = 'o'
a = 0.5
ms = 6
yfnt = 10
if len(x1)>0:
position+=1
ax1 = plt.subplot2grid((axis,1), (position, 0))
ax1.get_xaxis().get_major_formatter().set_useOffset(False)
a=ax1.scatter(x1, y1, s = ms, color = f, marker = m, alpha=0.5)
r=ax1.scatter(x1, z1, s = 2, color='black', marker= m, alpha=0.5, label='15min Rolling Avg')
ax1.set_xlim(min(x1), max(x1))
ax1.set_ylim(-0.01, max(y1)+1)
ax1.set_ylabel('[VOC] (ppm)', fontsize = yfnt)
for label in ax1.get_yticklabels():
label.set_fontsize(9)
for label in ax1.get_xticklabels():
label.set_fontsize(9)
ax1.xaxis.set_major_locator(hours)
ax1.set_xticklabels(ax1.xaxis.get_majorticklabels(), rotation=45)
ax1.xaxis.set_major_formatter(hoursFmt)
ax1.grid(b=True, axis='both', which ='major', color='black', linestyle='-', linewidth=1, alpha = 0.10)
if len(x2) > 0:
position+=1
ax2 = plt.subplot2grid((axis, 1), (position, 0))
ax2.get_xaxis().get_major_formatter().set_useOffset(False)
a=ax2.scatter(x2, y2, s = ms, color = f, marker = m, alpha=0.5)
r=ax2.scatter(x2, z2, s = 2, color='black', marker= m, alpha=0.5, label='15min Rolling Avg')
ax2.set_ylim(-0.01, max(y2)+1)
ax2.set_xlim(min(x2), max(x2))
ax2.set_ylabel('% LEL', fontsize = yfnt)
for label in ax2.get_yticklabels():
label.set_fontsize(9)
for label in ax2.get_xticklabels():
label.set_fontsize(9)
ax2.xaxis.set_major_locator(hours)
ax2.set_xticklabels(ax2.xaxis.get_majorticklabels(), rotation=45)
ax2.xaxis.set_major_formatter(hoursFmt)
ax2.grid(b=True, axis='both', which ='major', color='black', linestyle='-', linewidth=1, alpha = 0.10)
if len(x3) > 0:
position+=1
ax3 = plt.subplot2grid((axis, 1), (position, 0))
ax3.get_xaxis().get_major_formatter().set_useOffset(False)
a=ax3.scatter(x3, y3, s = ms, color = f, marker = m, alpha=0.5)
r=ax3.scatter(x3, z3, s = 2, color='black', marker= m, alpha=0.5, label = '15min Rolling Avg')
ax3.set_ylim(-0.01, max(y3)+5)
ax3.set_xlim(min(x3), max(x3))
ax3.set_ylabel('[Carbon Dioxide] (ppm)', fontsize = yfnt)
for label in ax3.get_yticklabels():
label.set_fontsize(9)
for label in ax3.get_xticklabels():
label.set_fontsize(9)
ax3.xaxis.set_major_locator(hours)
ax3.set_xticklabels(ax3.xaxis.get_majorticklabels(), rotation=45)
ax3.xaxis.set_major_formatter(hoursFmt)
ax3.grid(b=True, axis='both', which ='major', color='black', linestyle='-', linewidth=1, alpha = 0.10)
if len(x4) > 0:
position+=1
ax4 = plt.subplot2grid((axis, 1), (position, 0))
ax4.get_xaxis().get_major_formatter().set_useOffset(False)
a=ax4.scatter(x4, y4, s = ms, color = f, marker = m, alpha= 0.5)
r=ax4.scatter(x4, z4, s = 2, color='black', marker= m, alpha=0.5, label='15min Rolling Avg')
ax4.set_ylim(-0.01, max(y4)+1)
ax4.set_xlim(min(x4), max(x4))
ax4.set_ylabel('[Oxygen] (%)', fontsize = yfnt)
for label in ax4.get_yticklabels():
label.set_fontsize(9)
for label in ax4.get_xticklabels():
label.set_fontsize(9)
ax4.xaxis.set_major_locator(hours)
ax4.set_xticklabels(ax4.xaxis.get_majorticklabels(), rotation=45)
ax4.xaxis.set_major_formatter(hoursFmt)
ax4.grid(b=True, axis='both', which ='major', color='black', linestyle='-', linewidth=1, alpha = 0.10)
if len(x5) > 0:
position+=1
ax5 = plt.subplot2grid((axis, 1), (position, 0))
ax5.get_xaxis().get_major_formatter().set_useOffset(False)
a = ax5.scatter(x5, y5, color=f, s=ms, marker=m, alpha=0.5)
r = ax5.scatter(x5, z5, s = 2, color='black', marker= m, alpha=0.5, label='15min Rolling Avg')
ax5.set_ylim(-0.01, max(y5)+1)
ax5.set_xlim(min(x5), max(x5))
ax5.set_ylabel('[Methane] (ppm)', fontsize = yfnt)
for label in ax5.get_yticklabels():
label.set_fontsize(9)
for label in ax5.get_xticklabels():
label.set_fontsize(9)
ax5.xaxis.set_major_locator(hours)
ax5.set_xticklabels(ax5.xaxis.get_majorticklabels(), rotation=45)
ax5.xaxis.set_major_formatter(hoursFmt)
ax5.grid(b=True, axis='both', which ='major', color='black', linestyle='-', linewidth=1, alpha = 0.10)