【发布时间】:2011-09-15 05:09:42
【问题描述】:
我目前正在使用 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('Spam and Ham')
pyplot.xlabel('Time (in seconds)')
pyplot.ylabel('Bits of Ham')
pyplot.savefig(output_filename)
我想让 x 轴标签更有意义。
首先,这里的 x 轴刻度似乎被限制为五个刻度。无论我做什么,我似乎都无法改变这一点——即使我添加更多 xticklabels,它也只使用前五个。我不确定 Matplotlib 是如何计算的,但我认为它是根据范围/数据自动计算的?
有什么方法可以提高 x-tick 标签的分辨率 - 甚至可以提高每个条形图/bin 的分辨率?
(理想情况下,我还希望以微秒/毫秒为单位重新格式化秒,但这是另一天的问题)。
其次,我想标记每个单独的条 - 带有该箱中的实际数量,以及所有箱总数的百分比。
最终输出可能如下所示:
使用 Matplotlib 可以实现类似的功能吗?
干杯, 维克多
【问题讨论】:
标签: python matplotlib visualization histogram graphing