Matplotlib - 标记每个箱子
- 论坛
- Matplotlib - 标记每个箱子
9 浏览
Matplotlib - 标记每个箱子
我正在使用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和Ham') pyplot.xlabel('时间(秒)') pyplot.ylabel('Ham的比特数') pyplot.savefig(output_filename)
我想让x轴标签更有意义一些。
首先,这里的x轴刻度似乎限制为五个刻度。无论我做什么,似乎都无法改变这一点 - 即使我添加更多的xticklabels,它还是只使用前五个。我不确定Matplotlib是如何计算这个的,但我认为它是从范围/数据自动计算的?
有没有办法增加x轴刻度标签的分辨率 - 甚至每个柱/箱一个?
(理想情况下,我还希望将秒重新格式化为微秒/毫秒,但这是另一天的问题)。
其次,我想对每个单独的柱进行标记 - 包括该箱中的实际数字以及所有箱的总百分比。
最终的输出可能类似于这样:
使用Matplotlib是否有可能实现这样的效果?
谢谢,
Victor