Skip to content

Exported figures are in light mode independent of GUI styling - #247

Open
MikeSullivan7 wants to merge 5 commits into
RascalSoftware:mainfrom
MikeSullivan7:exporting_figures_light_mode
Open

Exported figures are in light mode independent of GUI styling#247
MikeSullivan7 wants to merge 5 commits into
RascalSoftware:mainfrom
MikeSullivan7:exporting_figures_light_mode

Conversation

@MikeSullivan7

Copy link
Copy Markdown
Collaborator

Instead of exporting the current figures, a temporary figure is created and the data is replotted using matplotlib default style and figure colours are explicitly set.

Now, using the Dark Theme:

image

Exports the following plots:

Main Window:

new

Bayes plots:

new_2

@MikeSullivan7

Copy link
Copy Markdown
Collaborator Author

All colour changes in exported figures now happen after the figure is drawn:

In dark mode, the exported plots are displayed as follows:

main shaded pos diog corner

@StephenNneji StephenNneji left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread rascal2/widgets/plot.py
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"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants