我想用matplotlib在此图表中添加低于x轴标签的平均速度。在使用一些硬编码文本测试后,我注意到它被剪裁了。我想打印#43; 43.2 km / h"低于时代。下面的示例代码
plt.hist(data, # data
30, # bins
None, # data range
False, # normalized
None, # weights
False, # cumulative
None, # bottom shift
'bar', # graph style
'mid', # bar positions
'vertical', # vertical/horizontal
None, # bar width
False, # log
None, # color
None, # label
False # stacked
)
ax = plt.gca()
ax.set_title(group + " Run")
ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.draw()
labels = []
for label in ax.get_xticklabels():
try:
t = timedelta(seconds=int(float(label.get_text())))
except ValueError:
t = label.get_text()
print ("(EE) x label problem in /tmp/run"+group+".svg")
label.set_text(str(t) + "\n43.2 km/h")
label.set_rotation(-45)
labels.append(label)
ax.set_xticklabels(labels)
plt.savefig("/tmp/run"+group+".svg")
plt.close('all')
标签循环将秒转换为您在下图中看到的格式化时间。