【问题标题】:Python matplotlib: customize the y-scale of a histogramPython matplotlib:自定义直方图的 y 尺度
【发布时间】:2017-05-04 02:18:50
【问题描述】:

我在 Python (3.4) Jupyter Notebook 中有以下代码来绘制直方图:

%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib
import numpy as np

bins = np.linspace(0, 1.0, 40)
plt.hist(list1, bins, alpha = 0.5, color = 'b')
plt.show()

我想知道我是否可以重新调整它以使 y 轴值的最大值为 100?谢谢!

【问题讨论】:

标签: python python-3.x matplotlib histogram jupyter-notebook


【解决方案1】:

这是一个 MWE:

import matplotlib.pyplot as plt
import numpy as np

bins = np.linspace(0, 1.0, 40)
y = np.random.rand(100) 

plt.hist(y, bins)
plt.ylim((None, 100))  # This line sets the y-axis limits

plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 2018-05-30
    • 2019-07-07
    • 1970-01-01
    相关资源
    最近更新 更多