-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH]: Sphinx plot directive to support dark mode #25983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
mechanistically, I expect this may be similar to #25515, just instead of dpi, would be theme... not quite sure how to hook into the browser, but conceptually it is similar, at least. I suspect that there are plenty of plots in our own docs that would not want it (e.g. when explicitly selecting colors that would not work on a dark background), but honestly many of them (if they are just using default color cycle/text colors), it may be better. I would expect to have a global toggle as well as an individual plot directive toggle. |
Update: I finally got around to try using https://github.com/scipy/scipy/blob/c1b803b66a3e9f0416f3feafc6d4cf24d2ec98e2/doc/source/_static/scipy.css#L133 in astropy but it didn't work. So I had to revert that change from astropy/astropy#15783 |
Does matplotlib have a native ability to make a dark mode version of a plot or would that setup have to be part of every plot directive codeblock? The way Furo handles this is it has I think this is solvable now by setting a custom template + custom pre_code that generates two plots and puts the appropriate classes on them. But that's not a good long term solution because the template is pretty complex and if you use a custom one, it would not stay updated with any upstream updates to the extension. |
Another option would be for matplotlib to generate SVGs that do the right thing in dark mode. Is that something that it already supports? See sympy/sympy#25702 for examples of how that can work. |
Problem
We are looking to deploy pydata-sphinx-theme on our docs (astropy/astropy#14867). The theme has a nifty light/dark mode toggle. Very quickly it is apparent that the generate plot using matplotlib's
.. plot::
directive stays in light mode no matter what. The result could be pretty jarring.Proposed solution
Would be nice for the
.. plot::
directive to follow light/dark mode. Though you might want it as opt-in just in case some users do not want that, especially if you decide to use the CSS color-inversion trick thatscipy
does in https://github.com/scipy/scipy/blob/c1b803b66a3e9f0416f3feafc6d4cf24d2ec98e2/doc/source/_static/scipy.css#L133 .Thank to @ksunden for pointing that out to me!
The text was updated successfully, but these errors were encountered: