【问题标题】:Histogram with base 2 logarithmic y-scale in matplotlib?matplotlib中以2为底的对数y标度的直方图?
【发布时间】:2013-04-22 13:04:33
【问题描述】:

有没有办法做到这一点?当我尝试指定 basebasey 时,hist 命令似乎无法识别它。

【问题讨论】:

  • 你能发布你已经尝试过的东西吗?

标签: python matplotlib histogram


【解决方案1】:

注意:以下解决方案适用于 matplotlib 版本


使用

ax.set_yscale('log', basey=2)

import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
fig, ax = plt.subplots()
x = mu + sigma * np.random.randn(10000)
ax.set_yscale('log', basey=2)
n, bins, histpatches = ax.hist(x, 50, facecolor='green', alpha=0.75)
plt.show()

【讨论】:

  • @twch:感谢您提出修改建议。 matplotlib 1.3.1 版中似乎存在回归,这导致仅绘制条形的顶部。不幸的是,我必须恢复您的编辑(使用 log=True),因为它还将 y 轴刻度更改为以 10 为底,而不是以 2 为底,这是这篇 SO 帖子试图解决的主要问题。
  • 请将此类问题报告为错误。
  • 而且它似乎是固定在master上,很快就会变成1.4.0。
猜你喜欢
  • 1970-01-01
  • 2017-05-04
  • 1970-01-01
  • 2020-05-20
  • 2012-06-14
  • 2017-11-17
  • 2019-07-07
  • 1970-01-01
  • 2019-02-25
相关资源
最近更新 更多