I am plotting a histogram with two sets of data and want to include a key. I have found an example that uses the label command, but when I use this it doesn't work. The histogram appears correctly, but there is no key. My code is.
H1 = <some data>
S1 = <some other data>
hist([H1,S1], bins=25, range=(10,30), align=('mid'), color=['green', 'orange'], label=['Actual H band', 'Actual IRAC2 band'])
title("Actual observed magnitudes of sources in H and IRAC2")
xlabel("Magnitude")
ylabel("Frequency")
show()
Any suggestions?
Create a dataset using numpy library so that we can plot it. Create a histogram using matplotlib library. To give labels use set_xlabel() and set_ylabel() functions. We add label to each bar in histogram and for that, we loop over each bar and use text() function to add text over it.
Look at a blank graph and identify its x and y-axis. The x-axis always runs horizontal -- along the bottom of the histogram and the y-axis runs vertical -- or lengthwise. Label the y-axis to identify what you are measuring.
To display the count over the bar in matplotlib histogram, we can iterate each patch and use text() method to place the values over the patches.
Create Histogram In Matplotlib, we use the hist() function to create histograms. The hist() function will use an array of numbers to create a histogram, the array is sent into the function as an argument.
Create a histogram using matplotlib library. To give labels use set_xlabel () and set_ylabel () functions. We add label to each bar in histogram and for that, we loop over each bar and use text () function to add text over it. We also calculate height and width of each bar so that our label don’t coincide with each other.
Create a dataset using numpy library so that we can plot it. Create a histogram using matplotlib library. To give labels use set_xlabel () and set_ylabel () functions. We add label to each bar in histogram and for that, we loop over each bar and use text () function to add text over it.
To plot a 2D histogram, one only needs two vectors of the same length, corresponding to each axis of the histogram. fig, ax = plt.subplots(tight_layout=True) hist = ax.hist2d(x, y) Customizing your histogram ¶ Customizing a 2D histogram is similar to the 1D case, you can control visual components such as the bin size or color normalization.
A histogram is a plot of the frequency distribution of numeric array by splitting it to small equal-sized bins. If you want to mathemetically split a given array to bins and frequencies, use the numpy histogram () method and pretty print it like below.
You have to include a legend call:
H1 = <some data>
S1 = <some other data>
hist([H1,S1], bins=25, range=(10,30), align=('mid'), color=['green', 'orange'], label=['Actual H band', 'Actual IRAC2 band'])
title("Actual observed magnitudes of sources in H and IRAC2")
xlabel("Magnitude")
ylabel("Frequency")
legend()
show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With