简体   繁体   中英

Python matplotlib: customize the y-scale of a histogram

I have the following code in Python (3.4) Jupyter Notebook to plot a histogram:

%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()

I am wondering can I rescale it so that the y-axis value has the maximum value of 100? Thanks!

Here is a 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM