【发布时间】:2014-04-18 10:33:47
【问题描述】:
我有以下数据集,我需要使用 matplotlib 为其生成箱线图:
[92,92,92,92,92,92,92,92,92,92,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95]
但我希望将箱形图的 y 轴分为以下区间:[64000-277231、277231-380059、380059-827581、827581-1338451、1338451-2593146、2593146-4559994] 和 x - 轴以 1 为间隔进行划分,即 [1,2,3,4,5,6,7,8,9]。我是 matplotlib 的新手,必须完成这项工作,我也提到了这篇文章。我编写了以下脚本来绘制箱线图,但我无法使用不同的 matplotlib 结构(如 xticks、yticks 和 xlim 和 ylim)来实现上述功能。
import numpy as np
import matplotlib as mpl
# agg backend is used to create the output file as a .png file
mpl.use('agg')
import matplotlib.pyplot as plt
plt.suptitle('Bitrate vs Trials', fontsize=15)
plt.ylabel("Bitrate")
plt.xlabel("Trials")
fig_instance = plt.figure(1 , figsize=(9,6))
ax_instance = fig_instance.add_subplot(111)
bp = ax_instance.boxplot(bitRateList)
# save the figure
fig_instance.savefig('a.png',bbox_inches='tight')
如何为上面的列表绘制图表。
【问题讨论】:
标签: python numpy matplotlib