hist
hist copied to clipboard
[FEATURE] Add high level API for ratio plot and pull plot to be plotted standalone
Describe the problem, if any, that your feature request is related to
A clear and concise description of what the problem is.
This might be getting into Issue #117 territory, but not that PR #161 there is the ability to make both ratio plots and pull plots with the .plot_ratio
and .plot_pull
APIs, but these both plot the participants of the fit or ratio on the top (main) axis and then the ratio or the pulls on a bottom (subplot) axis. There are times when one wants to be able to highlight features of the ratio / pulls by itself and in those situations having it on its own figure it desirable. As the matplotlib
API is setup to keep you from trying to copy axis objects around (c.f. details) it would be useful to have an API to plot the subplots by themselves.
Details:
Conversation on IRIS-HEP Slack on 2021-04-12:
@matthewfeickert: From my Stack Overflow searching tonight I think the answer is "no, because
matplotlib
intends for axes objects to be inherently linked to a singular figure.", but I'll ask thematplotlib
experts here: is there any non-super-hacky-breaking-the-API way to take a subplot that you've made and then copy it to a new figure as the only subplot if you wanted to look at it in more detail or blow it up to show some feature. I think the answer is "no, please just replot it".
Thomas Caswell: correct,
Axes
are deeply tied to theFigure
they are in (as we need transforms that go from data space -> screen space). In principle it should be possible to move Axes between figures, however in practice we do not have enough control of all of the connections between the Axes and the Figure to be sure we can do it correctly so we raise if you try! The best approach is to plot it again (and make sure you write your self enough helper functions that it is easy :wink: )
Support for this already exists in the form of
https://github.com/scikit-hep/hist/blob/deba9e4343e110c1b311d4a13ac5cb09ca8ced7a/src/hist/plot.py#L365
and
https://github.com/scikit-hep/hist/blob/deba9e4343e110c1b311d4a13ac5cb09ca8ced7a/src/hist/plot.py#L457
but it requires that the user do a bit of work (what is currently most of the logic in
https://github.com/scikit-hep/hist/blob/deba9e4343e110c1b311d4a13ac5cb09ca8ced7a/src/hist/plot.py#L506
) to get the ratio or pull np.ndarray
to then plot.
Describe the feature you'd like
A refactoring of the .plot_ratio
and .plot_pull
APIs to allow for a user to still have the ratio, fit, or pull calculations performed for them but then only plot the subplot of the ratio or pulls.
I'm happy to help on this, once there is a consensus on what to do.
Describe alternatives, if any, you've considered
As mentioned above, instead of doing this refactor in hist
migrate all of it to mplhep
as talked about in Issue #117.