'rasterio.plot.show_hist - How to change / modify x_label, y_label?

By default, rasterio.plot.show_hist(...) sets the histogram title to "Histogram", x_label to "DN" (for Digital Number) and y_label to "Frequency". There is a parameter for the 'title' but nothing for x_label and y_label.

How to change it? For example, to "Valeur numérique" and "Fréquence".

enter image description here



Solution 1:[1]

A solution I've found is to pass axes to the ax argument and after set axes.set_xlabel and axes.set_ylabel.

fig, axes = plt.subplots(figsize=(1.62*7,7))
rasterio.plot.show_hist(data,  
                    ... other parameters ...,
                    ax = axes,
                    title="Histogramme"
                   )
axes.set_xlabel("Valeur numérique")
_ = axes.set_ylabel("Fréquence")

enter image description here

Solution 2:[2]

##### import library #########################
from rasterio.plot import show_hist
######### Set figure dimensions and axes   ###################
fig, (axrgb, axhist) = plt.subplots(1, 2, figsize=(14,7))
################ plot raster ########################
show(src, ax=axrgb)
################ plot histogram of raster ########################
show_hist(src, bins=100, histtype='stepfilled',lw=0.0, stacked=False, alpha=0.3, ax=axhist)
################ set x axis limits of histogram ########################
plt.xlim(xmin=0, xmax = 50)
################ set x axis label of Histogram ########################
axhist.set_xlabel('Soil Mositure')
################ set y axis label of Histogram ########################
axhist.set_ylabel('Frequency')

################ set title of Histogram ######################## axhist.set_title('Maharashtra')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Claude COULOMBE
Solution 2 Abhilash Singh Chauhan