Exported figures are in light mode independent of GUI styling - #247
Open
MikeSullivan7 wants to merge 5 commits into
Open
Exported figures are in light mode independent of GUI styling#247MikeSullivan7 wants to merge 5 commits into
MikeSullivan7 wants to merge 5 commits into
Conversation
Collaborator
Author
StephenNneji
approved these changes
Aug 20, 2026
StephenNneji
left a comment
Contributor
There was a problem hiding this comment.
Works as advertised, the figure deep copy is still a bit slow but significantly better than before so we can live with it. thanks. please see comment below
| if scheme == QtCore.Qt.ColorScheme.Light: | ||
| self.figure.savefig(filepath, facecolor=SETTINGS.export_background_colour, dpi=dpi) | ||
| else: | ||
| old_colours = matplotlib.rcParams["axes.prop_cycle"].by_key()["color"] |
Contributor
There was a problem hiding this comment.
I suggest a refactor to get rid of hardcoded colours, let me know if it works
old_colours = matplotlib.rcParams["axes.prop_cycle"].by_key()["color"]
with matplotlib.style.context("default"):
edge_colour = matplotlib.rcParams['axes.edgecolor']
face_colour = matplotlib.rcParams['axes.facecolor']
new_colours = matplotlib.rcParams["axes.prop_cycle"].by_key()["color"]
colour_converter = dict(zip(old_colours, new_colours, strict=False))
temp_fig = copy.deepcopy(self.figure)
axes = temp_fig.axes
for ax in axes:
if not ax.get_visible():
continue
if ax.containers:
for container in ax.containers:
if isinstance(container, matplotlib.container.ErrorbarContainer):
_, __, (vertical_lines,) = container.lines
vertical_lines.set_color(
colour_converter[
matplotlib.colors.rgb2hex(vertical_lines.get_color(), keep_alpha=False)
]
)
ax.patch.set_facecolor(face_colour)
for spine in ax.spines.values():
spine.set_edgecolor(edge_colour)
ax.tick_params(which="both", axis="both", color="black", labelcolor=edge_colour)
ax.xaxis.label.set_color(edge_colour)
ax.yaxis.label.set_color(edge_colour)
ax.set_title(ax.get_title(loc="left"), color=edge_colour, loc="left")
if ax.get_legend() is not None:
ax.legend(facecolor="white", labelcolor=edge_colour)
for line in ax.get_legend().get_lines():
old_line_colour = line.get_color()
line.set_color(colour_converter[old_line_colour])
for line in ax.get_lines():
old_line_colour = line.get_color()
line.set_color(colour_converter[old_line_colour])
temp_fig.savefig(filepath, facecolor=SETTINGS.export_background_colour, dpi=dpi)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





Instead of exporting the current figures, a temporary figure is created and the data is replotted using
matplotlibdefault style and figure colours are explicitly set.Now, using the Dark Theme:
Exports the following plots:
Main Window:
Bayes plots: