Python matplotlib:自定义直方图的y尺度

时间:2016-12-19 04:15:27

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

我在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吗?谢谢!

1 个答案:

答案 0 :(得分:0)

这是一个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()