Skip to content

Commit 860ff81

Browse files
committed
Faster import in load_mplstyle
Importing `matplotlib.style` is faster than `matplotlib.pyplot`.
1 parent 278f531 commit 860ff81

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

stagpy/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _check_config() -> None:
7272

7373
def load_mplstyle() -> None:
7474
"""Try to load conf.plot.mplstyle matplotlib style."""
75-
import matplotlib.pyplot as plt
75+
import matplotlib.style as mpls
7676
if conf.plot.mplstyle:
7777
for style in conf.plot.mplstyle.split():
7878
found = False
@@ -87,11 +87,12 @@ def load_mplstyle() -> None:
8787
if stfile.is_file():
8888
style = str(stfile)
8989
try:
90-
plt.style.use(style)
90+
mpls.use(style)
9191
except OSError:
9292
print(f'Cannot import style {style}.', file=sys.stderr)
9393
conf.plot.mplstyle = ''
9494
if conf.plot.xkcd:
95+
import matplotlib.pyplot as plt
9596
plt.xkcd()
9697

9798

0 commit comments

Comments
 (0)