[SUPPORT] how to label the vertical axis for a 1D histogram
goi42 opened this issue · comments
I feel foolish, but I cannot figure out how to assign a label to the vertical axis on a 1D histogram, nor can I find any examples showing such a thing.
Hi @goi42, I think you can pass keyword arguments from hist
through to matplotlib
when plotting, but axis labels are not supported through keyword arguments as far as I know. It is possible to set the label directly with matplotlib
though. There are different patterns available with various pieces of matplotlib
API, here is an example that creates a figure and axes ahead of the histogram plotting call and then sets the label:
import hist
import matplotlib.pyplot as plt
h = hist.Hist.new.Regular(1, 0, 1, name="variable").Double()
h.fill([0.5])
fig, ax = plt.subplots()
a = h.plot(ax=ax) # plot on the axes created
ax.set_ylabel("abc") # set desired label
fig.savefig("fig.png") # fig object provides access to the figure
Another version:
import hist
import matplotlib.pyplot as plt
h = hist.Hist.new.Regular(1, 0, 1, name="variable").Double()
h.fill([0.5])
h.plot()
plt.ylabel("abc")
plt.gcf().savefig("a.png")
Okay, it's good to know I didn't overlook something. I've opened feature request #431.