I'm trying to create a histogram of a data column and plot it logarithmically (y-axis
) and I'm not sure why the following code does not work:
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('foo.bar')
fig = plt.figure()
ax = fig.add_subplot(111)
plt.hist(data, bins=(23.0, 23.5,24.0,24.5,25.0,25.5,26.0,26.5,27.0,27.5,28.0))
ax.set_xlim(23.5, 28)
ax.set_ylim(0, 30)
ax.grid(True)
plt.yscale('log')
plt.show()
I've also tried instead of plt.yscale('log')
adding Log=true
in the plt.hist
line and also I tried ax.set_yscale('log')
, but nothing seems to work. I either get an empty plot, either the y-axis
is indeed logarithmic (with the code as shown above), but there is no data plotted (no bins).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…