Skip to content

Commit

Permalink
fix: faster label drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejnovak committed May 23, 2022
1 parent ed43c54 commit ec69377
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/mplhep/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ def dist(tup):
_exp_loc = 1
_formater = ax.get_yaxis().get_major_formatter()
if type(mpl.ticker.ScalarFormatter()) == type(_formater) and _exp_loc == 0:
ax.figure.canvas.draw()
_sci_box = pixel_to_axis(ax.get_yaxis().offsetText.get_window_extent())
_sci_box = pixel_to_axis(
ax.get_yaxis().offsetText.get_window_extent(ax.figure.canvas.get_renderer())
)
_sci_offset = _sci_box.width * 1.1
loc1_dict[_exp_loc]["xy"] = (_sci_offset, loc1_dict[_exp_loc]["xy"][-1])
if loc == 0:
Expand All @@ -143,9 +144,10 @@ def dist(tup):
)
ax._add_text(exptext)

ax.figure.canvas.draw()
_dpi = ax.figure.dpi
_exp_xoffset = exptext.get_window_extent().width / _dpi * 1.05
_exp_xoffset = (
exptext.get_window_extent(ax.figure.canvas.get_renderer()).width / _dpi * 1.05
)
if loc == 0:
_t = mtransforms.offset_copy(
exptext._transform, x=_exp_xoffset, units="inches", fig=ax.figure
Expand Down
Binary file modified tests/baseline/test_style_alice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_style_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_style_cms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_style_lhcb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_style_lhcb2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions tests/test_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_style_atlas():
fig, ax = plt.subplots()
hep.atlas.label(label="Preliminary")

plt.rcParams.update(plt.rcParamsDefault)
return fig


Expand All @@ -46,7 +45,6 @@ def test_style_cms():
fig, ax = plt.subplots()
hep.cms.label("Preliminary")

plt.rcParams.update(plt.rcParamsDefault)
return fig


Expand All @@ -59,7 +57,6 @@ def test_style_alice():
fig, ax = plt.subplots()
hep.alice.label("Preliminary")

plt.rcParams.update(plt.rcParamsDefault)
return fig


Expand All @@ -70,8 +67,7 @@ def test_style_lhcb():

plt.style.use([hep.style.LHCb1, {"figure.autolayout": False}])
fig, ax = plt.subplots()
hep.lhcb.label()
plt.rcParams.update(plt.rcParamsDefault)
hep.lhcb.label("Preliminary")
return fig


Expand All @@ -82,8 +78,7 @@ def test_style_lhcb2():

plt.style.use([hep.style.LHCb2, {"figure.autolayout": False}])
fig, ax = plt.subplots()
hep.lhcb.text()
plt.rcParams.update(plt.rcParamsDefault)
hep.lhcb.label("Preliminary")
return fig


Expand Down

0 comments on commit ec69377

Please sign in to comment.