【发布时间】:2011-09-14 13:32:39
【问题描述】:
1. X-ticklabels 不起作用
我正在使用 Matplotlib 从一些测量中生成直方图:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as pyplot
...
fig = pyplot.figure()
ax = fig.add_subplot(1,1,1,)
n, bins, patches = ax.hist(measurements, bins=50, range=(graph_minimum, graph_maximum), histtype='bar')
ax.set_xticklabels([n], rotation='vertical')
for patch in patches:
patch.set_facecolor('r')
pyplot.title='Foobar'
#pyplot.grid(True)
pyplot.xlabel('X-Axis')
pyplot.ylabel('Y-Axis')
pyplot.savefig(output_filename)
生成的 PNG 看起来不错,除了两个问题:
- PNG 中缺少标题(“Spam and Ham”)。 x 和 y 轴标签都存在(尽管我没有为下面的示例打开它们)。
- x-tick-lables 似乎完全损坏了 - 它没有显示在所有条形下方的底部,而是呈现为图形左下方下方的单行数字,被截断。它似乎也禁用了我的 Y 轴标签。
2。单位和 SI 前缀
注意:不是 Matplotlib 特定的。
直方图沿 x 轴具有时间测量值。这些范围从微秒范围到毫秒和秒范围。目前,该图将 x 轴标签呈现为标准表示法中的秒数。
我想要友好的格式我宁愿时间以毫秒/微秒的值给出,并显示单位。所以这意味着我想要一些东西来友好地格式化时间值,并注意 SI 前缀。
实际上,它可能与这里的示例程序非常相似:
http://diveintopython3.org/your-first-python-program.html
我确实注意到有一些 Python 库可以处理单元:
- http://juanreyero.com/open/magnitude/index.html
- http://home.scarlet.be/be052320/Unum.html
- http://pypi.python.org/pypi/units/
但是,根据我的阅读,上面的任何处理 SI 前缀似乎都没有,也没有进行这种友好的格式化。有什么建议/替代方案吗?
【问题讨论】:
标签: python matplotlib histogram graphing