hist icon indicating copy to clipboard operation
hist copied to clipboard

[FEATURE] Assign value-axis label

Open goi42 opened this issue 2 years ago • 0 comments

I would like to be able to assign a label to the value axis of a histogram, e.g., the vertical axis of a 1D histogram. (See #425.)

Why:

  1. The meaning of the value axis is a property of the histogram, so it makes logical sense that it would be a property of the Hist object.
    1. That is to say, the appropriate value-axis label can vary wildly between histograms, especially if they were weighted, normalized, or represent some physical parameter value.
  2. It streamlines coding.
    1. As it is, I have to retrieve it from the metadata (or just remember what it means) and plot it manually.
    2. This is particularly egregious when one saves the histogram to a file for later retrieval. Using uproot, for example, one currently ends up saving a 1D histogram as a TH1D with an x-axis label and no y-axis label. Any metadata is lost, so if one wants to save the y-axis label, one has to store it as a separate object in the file.

Example of desired behavior:

import hist

h = hist.Hist(hist.axis.Regular(50, 0, 50, label="x"), count_label="y")
h.plot()

Approximately equivalent to:

import hist
import matplotlib.pyplot as plt

h = hist.Hist(hist.axis.Regular(50, 0, 50, label="x"))
fig, ax = plt.subplots()
a = h.plot(ax=ax)
ax.set_ylabel("y")

goi42 avatar Jul 13 '22 14:07 goi42