Skip to content

Commit 93190c1

Browse files
committed
Fixed bug with priority of rcParams
In version 4.0.0 I added theme="default", which was then going to be applied every time a new figure was instantiated. Turns out that setting a theme with `plt.style.context(theme)` is going to disregard user-provided settings with `plt.rcParams`. This commit sets theme="", which would still use Matplotlib default theme, but it will be loaded through rcParams. So any user-provided settings to rcParams will be applied to the figure, provided that theme="".
1 parent ec46ccc commit 93190c1

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

spb/backends/matplotlib/matplotlib.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(self, *args, **kwargs):
154154
"use_latex", cfg["matplotlib"]["use_latex"])
155155
kwargs.setdefault("grid", cfg["matplotlib"]["grid"])
156156
kwargs.setdefault("minor_grid", cfg["matplotlib"]["show_minor_grid"])
157-
kwargs.setdefault("theme", "default")
157+
kwargs.setdefault("theme", "")
158158
super().__init__(*args, **kwargs)
159159

160160
# set labels
@@ -634,10 +634,21 @@ def draw(self):
634634
# create the figure from scratch every time, otherwise if the plot was
635635
# previously shown, it would not be possible to show it again. This
636636
# behaviour is specific to Matplotlib
637-
with self.plt.style.context(self.theme):
637+
def func():
638638
self._create_figure()
639639
self._process_renderers()
640640

641+
# NOTE: when applying a theme, plt.rcParams is not considered.
642+
# So, any user settings to plt.rcParams will be disregarded.
643+
# The following if/else assures that if no theme is provided, then
644+
# plt.rcParams are going to be considered.
645+
646+
if self.theme:
647+
with self.plt.style.context(self.theme):
648+
func()
649+
else:
650+
func()
651+
641652
process_series = draw
642653

643654
def show(self, **kwargs):

0 commit comments

Comments
 (0)