Monday, 15 June 2015

python - Multiple step histograms in matplotlib -



python - Multiple step histograms in matplotlib -

dear python/matplotlib community,

i having issue within matplotlib: can't seem plot multiple overlaid histograms in same plot space using following:

binsize = 0.05 min_x_data_sey, max_x_data_sey = np.min(logoii_oiii_sey), np.max(logoii_oiii_sey) num_x_bins_sey = np.floor((max_x_data_sey - min_x_data_sey) / binsize) min_x_data_comp, max_x_data_comp = np.min(logoii_oiii_comp), np.max(logoii_oiii_comp) num_x_bins_comp = np.floor((max_x_data_comp - min_x_data_comp) / binsize) min_x_data_sf, max_x_data_sf = np.min(logoii_oiii_sf), np.max(logoii_oiii_sf) num_x_bins_sf = np.floor((max_x_data_sf - min_x_data_sf) / binsize) axscatter_farright = fig.add_subplot(gs_right[0,0]) axscatter_farright.tick_params(axis='both', which='major', labelsize=10) axscatter_farright.tick_params(axis='both', which='minor', labelsize=10) axscatter_farright.set_ylabel(r'$\mathrm{n}$', fontsize='medium') axscatter_farright.set_xlim(-1.5, 1.0) axscatter_farright.set_xlabel(r'$\mathrm{log([oii]/[oiii])}$', fontsize='medium') axscatter_farright.hist(logoii_oiii_sey, num_x_bins_sey, ec='0.3', fc='none', histtype='step') axscatter_farright.hist(logoii_oiii_comp, num_x_bins_comp, ec='0.3', fc='none', histtype='step') axscatter_farright.hist(logoii_oiii_sf, num_x_bins_sf, ec='0.3', fc='none', histtype='step')

it seems axes class can not handle multiple histograms? please right me if and/or have gone wrong.

my overall plot 1 row, 3 column plotting space. utilize grid spec give plots layout.

this plot looks far:

this want histogram portion of figure in terms of step type histogram overlays (with legend):

i have datasets 3 different tuple type arrays generated csv file. i.e., using x, y = np.genfromtext(datafile.csv)

if able explain how done appreciative.

what you're doing should work perfectly. possible 1 of distributions in x-range of -1.5 1 you've set couple of lines before? (i.e. seek removing manual set_xlim statement , see if other distributions show up.)

as quick, stand-alone illustration demonstrate things should work:

import numpy np import matplotlib.pyplot plt num = 1000 d1 = np.random.normal(-1, 1, num) d2 = np.random.normal(1, 1, num) d3 = np.random.normal(0, 3, num) fig, ax = plt.subplots() ax.hist(d1, 50, ec='red', fc='none', lw=1.5, histtype='step', label='dist a') ax.hist(d2, 50, ec='green', fc='none', lw=1.5, histtype='step', label='dist b') ax.hist(d3, 100, ec='blue', fc='none', lw=1.5, histtype='step', label='dist c') ax.legend(loc='upper left') plt.show()

(if want legend show lines instead of boxes, you'll need utilize proxy artist. can add together illustration if you'd like. that's outside scope of question, though.)

python matplotlib plot histogram

No comments:

Post a Comment