Hello I'm trying to plot a histogram in Python. The y-axis needs to go up to values of 1e+19 and the x axis need to be from 0 to 10. I'm confused because I'm not sure how python is plotting this. I think it's graphing my y-axis data matrix on the x-axis.
flux_norm= (np.multiply(n,flux))
plt.hist(flux_norm, bins=30)
plt.xlim(0,10)
plt.ylim(0,10**19)
plt.title("Histogram of Normalized Flux")
plt.xlabel("Energy (MeV)")
plt.ylabel("Normalized flux")
The code above gives me a blank graph
flux_norm= (np.multiply(n,flux))
plt.hist(flux_norm, bins=30)
plt.title("Histogram of Normalized Flux")
plt.xlabel("Energy (MeV)")
plt.ylabel("Normalized flux")
The code above gives me a graph but only sets my y-axis to 2! and my x-axis is at 1e+19
Ive looked at the general ways to graph histograms on python but I can't find an example that's similar to my case. please send help
You second code should work just fine, this outputs the following histogram:
import matplotlib.pyplot as plt
import numpy as np
flux = np.arange(1,10**19,10**17)
n = np.arange(0,100,1)
flux_norm= (np.multiply(n,flux))
plt.hist(flux_norm, bins = 30)
##plt.xlim(0,10)
##plt.ylim(0,10**19)
plt.title("Histogram of Normalized Flux")
plt.xlabel("Energy (MeV)")
plt.ylabel("Normalized flux")
plt.show()
Obviously, in the first case there are no data plotted in the visible range of
plt.xlim(0,10)
plt.ylim(0,10**19)
Here is how first argument x
in hist
works - from matplotlib.pyplot docs
x : (n,) array or sequence of (n,) arrays
Input values, this takes either a single array or a sequency of arrays which are not required to be of the same length
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.