scikit-hep / mplhep

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
https://mplhep.readthedocs.io
MIT License
185 stars 64 forks source link

Redundant x/y-label customization? #300

Open andrzejnovak opened 3 years ago

andrzejnovak commented 3 years ago

@kratsg @matthewfeickert Are these still needed? https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/atlas.py#L52

The label position should be configurable in the style (seems we already have that) https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/styles/atlas.py#L51

kratsg commented 3 years ago

Those are different things. The style doesn't control where to anchor the bounding box of the text labels in matplotlib.

andrzejnovak commented 3 years ago

@kratsg what am I missing

import mplhep as hep
import matplotlib.pyplot as plt
import numpy as np
hep.style.use("ATLAS")

np.random.seed(0)
h, bins = np.histogram(np.random.normal(10, 3, 400), bins=10)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5))

hep.histplot(h, bins, ax=ax1)
hep.atlas.set_xlabel("FOO", ax=ax1)
hep.atlas.set_ylabel("FOO", ax=ax1)

hep.histplot(h, bins, ax=ax2)
ax2.set_xlabel("BAR")
ax2.set_ylabel("BAR")

image

andrzejnovak commented 2 years ago

@kratsg bump, newer mpl has the rcConfigs to do this

    "xaxis.labellocation": "right",
    "yaxis.labellocation": "top",
kratsg commented 2 years ago

should confirm then we can drop. one tricky thing is to make sure the horizontal alignment/vertical alignment is set correctly even if the label location is configurable. Each axis treats it differently which is why it was a bit annoying.