I have load raster (Sentinel 2) with Rasterio and I would like to create histogram of the pixels. The problem is that I beleive the graph gives automatically the X label and also the legend labels.

This is how I create the histogram:


from rasterio.plot import show_hist
plt.xlim(xmin=0, xmax = 1)
show_hist(his_data, bins=200, lw=0.0, stacked=False, alpha=0.8,histtype='stepfilled', title="Histogram")

and this is what I get- the legend labels are not like the bands and the x axis called DN even though my image is reflectance and I defined it as reflectance:
enter image description here

is there any way to control this ? or I need to change it into array and then plot it

1 Answer 1


Try creating the figure and axis explicitly:

fig, axhist = plt.subplots(1, 1)
show_hist(hist_data, bins=200, histtype='stepfilled',
          lw=0.0, stacked=False, alpha=0.8, ax=axhist)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.