Re: Toggling dark/light GUI mode / changing matplotlib style

Matt Newville <[email protected]> Fri, 4 Mar 2022 22:24:17 -0600
Newsgroups gmane.comp.python.wxpython
Message-ID <CA+7ESbq6S0KwLCS_jjJxw6fMenDqs+qAMJyQ89vj8o5sXiez9Q@mail.gmail.com>
--000000000000533ded05d97103a8
Content-Type: text/plain; charset="UTF-8"

Example code is always preferred.
But also: you might find wxmplot (
https://newville.github.io/wxmplot/index.html) useful, either for the
wxmplot.PlotPanel - a subclass of wx.Panel, and containing a matplotlib
plot - that it provides, or for the code to show how matplotlib and
wxPython can work together.  For example, each PlotPanel can be configured
by the end-user after being displayed to change plot properties (line
width, join style, colors, margins, labels, etc).    One of the things it
supports is setting one of matplolib's color themes (including many from
seaborn).  This essentially sets the matplotlib rcParams settings and sets
the colors of the various plot components.




On Fri, Mar 4, 2022 at 4:02 PM Matthias Brennwald <[email protected]>
wrote:

> Hello
>
> I am working on a program that uses a wx panel with a matplotlib figure.
> If the user toggles the GUI environment from light to dark mode (or vice
> versa), the GUI elements provided by wx will follow the change nicely, but
> the matplotlib figure will not. I am using the 'default' plot styles for
> matplotlib when my program detects the "light" GUI setting during startup,
> while the 'dark_background' style is used if the "dark" setting is detected
> at startup (like this:
> https://matplotlib.org/3.1.0/gallery/style_sheets/dark_background.html ).
>
> While setting the correct matplotlib style works fine at startup, things
> get more difficult if I am trying to change the style after the user
> toggles the "light" / "dark" mode. I worked out how the the change can be
> detected in a handler for the wx.EVT_PAINT event. However, once the GUI
> style change is detected, matplotlib does not seem to allow applying a
> different matplotlib style to the existing plot panel. It looks like the
> whole matplotlib figure would need to be re-created from scratch in order
> to apply the correct plot style. However, this is not (easily) possible in
> my application.
>
> I'd appreciate any pointers or suggestions on how to deal with "light" /
> "dark" mode changes in wx/matplotlib panels.
>
> Matthias
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wxpython-users/OKQ88R.NFAW8S5P52GH%40gmail.com
> <https://groups.google.com/d/msgid/wxpython-users/OKQ88R.NFAW8S5P52GH%40gmail.com?utm_medium=email&utm_source=footer>
> .
>


--Matt

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CA%2B7ESbq6S0KwLCS_jjJxw6fMenDqs%2BqAMJyQ89vj8o5sXiez9Q%40mail.gmail.com.

--000000000000533ded05d97103a8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:arial,sans-serif">Example code is always preferred.=C2=A0=C2=A0</d=
iv><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif">But =
also: you might find wxmplot (<a href=3D"https://newville.github.io/wxmplot=
/index.html">https://newville.github.io/wxmplot/index.html</a>) useful, eit=
her for the wxmplot.PlotPanel - a subclass of wx.Panel, and containing a ma=
tplotlib plot - that it provides, or for the code to show how matplotlib an=
d wxPython can work together.=C2=A0 For example, each PlotPanel can be conf=
igured by the end-user after being displayed to change plot properties (lin=
e width, join style, colors, margins, labels, etc).=C2=A0 =C2=A0 One of the=
 things it supports is setting one of matplolib&#39;s=C2=A0color themes (in=
cluding many from seaborn).=C2=A0 This essentially sets the matplotlib rcPa=
rams settings and sets the colors of the various=C2=A0plot components.</div=
><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif"><br></=
div><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif"><br=
></div><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif">=
=C2=A0</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"=
gmail_attr">On Fri, Mar 4, 2022 at 4:02 PM Matthias Brennwald &lt;<a href=
=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l=
eft:1px solid rgb(204,204,204);padding-left:1ex"><div id=3D"gmail-m_-512297=
3989640837802geary-body" dir=3D"auto"><div>Hello</div><div><br></div><div>I=
 am working on a program that uses a wx panel with a matplotlib figure. If =
the user toggles the GUI environment from light to dark mode (or vice versa=
), the GUI elements provided by wx will follow the change nicely, but the m=
atplotlib figure will not. I am using the &#39;default&#39; plot styles for=
 matplotlib when my program detects the &quot;light&quot; GUI setting durin=
g startup, while the &#39;dark_background&#39; style is used if the &quot;d=
ark&quot; setting is detected at startup (like this:=C2=A0<a href=3D"https:=
//matplotlib.org/3.1.0/gallery/style_sheets/dark_background.html" target=3D=
"_blank">https://matplotlib.org/3.1.0/gallery/style_sheets/dark_background.=
html</a> ).</div><div><br></div><div>While setting the correct matplotlib s=
tyle works fine at startup, things get more difficult if I am trying to cha=
nge the style after the user toggles the &quot;light&quot; / &quot;dark&quo=
t; mode. I worked out how the the change can be detected in a handler for t=
he wx.EVT_PAINT event. However, once the GUI style change is detected, matp=
lotlib does not seem to allow applying a different matplotlib style to the =
existing plot panel. It looks like the whole matplotlib figure would need t=
o be re-created from scratch in order to apply the correct plot style. Howe=
ver, this is not (easily) possible in my application.</div><div><br></div><=
div>I&#39;d appreciate any pointers or suggestions on how to deal with &quo=
t;light&quot; / &quot;dark&quot; mode changes in wx/matplotlib panels.</div=
><div><br></div><div>Matthias</div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/OKQ88R.NFAW8S5P52GH%40gmail.com?utm_medium=3Demai=
l&amp;utm_source=3Dfooter" target=3D"_blank">https://groups.google.com/d/ms=
gid/wxpython-users/OKQ88R.NFAW8S5P52GH%40gmail.com</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div><div dir=3D"ltr" class=
=3D"gmail_signature"><div dir=3D"ltr">--Matt=C2=A0<br></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxpy=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/CA%2B7ESbq6S0KwLCS_jjJxw6fMenDqs%2BqAMJyQ89vj8o5s=
Xiez9Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://gro=
ups.google.com/d/msgid/wxpython-users/CA%2B7ESbq6S0KwLCS_jjJxw6fMenDqs%2BqA=
MJyQ89vj8o5sXiez9Q%40mail.gmail.com</a>.<br />

--000000000000533ded05d97103a8--