【问题标题】:matplotlib bar plot adjust bar directionmatplotlib 条形图调整条形方向
【发布时间】:2015-05-27 11:23:48
【问题描述】:

我想从底部开始。如何将起点从零更改为例如-2 ?

我的代码:

import matplotlib.pyplot as plt
import numpy as np


N=1000
sample=np.random.random_integers(1,10,N)
hist,bins=np.histogram(sample)

plt.bar(bins[:-1],np.log10(1.*hist/N),np.diff(bins))

plt.show()

输出:

【问题讨论】:

  • 抱歉,因为我意识到另一件事,所以删除了评论。我想你会发现它确实发生了变化,但只是轻微的变化。

标签: python matplotlib plot axes


【解决方案1】:

试试这个:

plt.bar(bins[:-1],abs(np.log10(1.*hist/N)),np.diff(bins))

【讨论】:

  • 我想保持 y 轴标签不变,因为它是对数
  • Hardythe1 是在正确的轨道上。现在只需在 plt.bar() 中添加 bottom=-2
  • 谢谢!现在工作了:plt.bar(bins[:-1],2-abs(np.log10(1.*hist/N)),np.diff(bins),bottom=-2)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-27
  • 2015-12-25
  • 2016-01-02
  • 1970-01-01
  • 1970-01-01
  • 2018-08-22
相关资源
最近更新 更多