【问题标题】:Matplotlib Histogram plot : limiting x axis with max value without ignoring records that exceeds that valueMatplotlib直方图:用最大值限制x轴而不忽略超过该值的记录
【发布时间】:2020-03-08 08:35:36
【问题描述】:

我有一个大约 30k 值的列表要绘制到 matplotlib 直方图中,大多数值在 1 到 500 之间,这使得该区域范围内的条形清晰可见,而 500 以上的条形几乎不可见(您可以查看附图) 我想将 x 轴限制为最大值(如 1000)但不忽略高于 1000 的列表值,有没有办法将直方图限制为 1000(plt.xlim(xmax=1000))但不忽略更大的值大于 1000(我们在直方图中添加最后一个柱,显示所有大于 1000 的列表值的积云)

代码如下:

commutes =  pd.Series( (v for v in nb_posts_user_list) ) # nb_posts_user_list contain around 30k values between 1 and 3000
binwidth=10
commutes.plot.hist(grid=True,color='r', alpha=0.5, label='x',bins=range(min(commutes), max(commutes) + binwidth, binwidth))
plt.xlim(xmin=0)
#plt.xlim(xmax=1000)
plt.ylim(ymin=0)
#plt.xlabel('Average tweet length (Number of char)')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.grid(axis='y', alpha=0.75)
plt.show()

我得到这个直方图

【问题讨论】:

    标签: python matplotlib plot graph histogram


    【解决方案1】:

    我想你唯一的办法就是限制垃圾箱,所以,你最好选择一个较低的值(1000),而不是bins=range(min(commutes), max(commutes) + binwidth, binwidth) 中的max(commutes

    其他方式可以用不同的(对数?)标度来描述您的 y 值。

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 2021-03-24
      • 1970-01-01
      • 2018-02-25
      • 2015-07-10
      • 1970-01-01
      相关资源
      最近更新 更多