Skip to content

Commit 05ce3ce

Browse files
authored
Merge pull request #34 from jklymak/enh-add-theme-switcher
Enh add theme switcher
2 parents 7d503df + 6954723 commit 05ce3ce

File tree

8 files changed

+620
-18
lines changed

8 files changed

+620
-18
lines changed

docs/conf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import time
33
import datetime
4-
4+
import matplotlib # noqa: F401
55
# Configuration file for the Sphinx documentation builder for
66
# matplotlib projects.
77

@@ -28,7 +28,9 @@
2828
# Add any Sphinx extension module names here, as strings. They can be
2929
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3030
# ones.
31-
extensions = []
31+
extensions = [
32+
'matplotlib.sphinxext.plot_directive',
33+
]
3234

3335
# Add any paths that contain templates here, relative to this directory.
3436

@@ -42,7 +44,9 @@
4244
html_theme = "mpl_sphinx_theme"
4345
html_favicon = "_static/favicon.ico"
4446
html_theme_options = {
45-
"logo": {"link": "https://matplotlib.org/stable/"},
47+
"logo": {"link": "https://matplotlib.org/stable/",
48+
"image_light": "images/logo2.svg",
49+
"image_dark": "images/logo_dark.svg"},
4650
# collapse_navigation in pydata-sphinx-theme is slow, so skipped for local
4751
# and CI builds https://github.com/pydata/pydata-sphinx-theme/pull/386
4852
"collapse_navigation": not is_release_build,

docs/index.rst

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Welcome to Matplotlib Sphinx Theme's documentation!
55
:maxdepth: 2
66
:caption: Contents:
77

8-
This is the official Sphinx theme for Matplotlib documentation.
9-
It extends the ``pydata_sphinx_theme`` project, but adds custom
8+
This is the official Sphinx theme for Matplotlib documentation.
9+
It extends the ``pydata_sphinx_theme`` project, but adds custom
1010
styling and a navigation bar.
1111

1212
When creating a Matplotlib subproject you can include this theme by changing this
@@ -25,18 +25,55 @@ There are three main templates that replace the defaults in ``pydata-sphinx-them
2525
2626
navbar_start = mpl_navbar_logo.html
2727
navbar_center = mpl_nav_bar.html
28-
navbar_end = mpl_icon_links.html
28+
navbar_end = mpl_icon_links.html
2929
30-
Note that the option ``html_logo`` need not be specified as it is included
31-
in ``mpl_sphinx_theme/mpl_navbar_logo.html``. The logo is stored at
32-
``mpl_sphinx_theme/static/images/logo2.svg``.
30+
Note that the option ``html_logo`` need not be specified as it is included
31+
in ``mpl_sphinx_theme/mpl_navbar_logo.html``. The logo is stored at
32+
``mpl_sphinx_theme/static/images/logo2.svg``.
3333

3434
To change the top navbar, edit ``mpl_sphinx_theme/mpl_nav_bar.html``
3535

3636
To change the social icons, edit ``mpl_sphinx_theme/mpl_icon_links.html``
3737

3838
To change the style, edit ``mpl_sphinx_theme/static/css/style.css``
3939

40-
The full ``conf.py`` is
40+
Example plot
41+
~~~~~~~~~~~~
42+
.. plot::
43+
:include-source:
44+
:align: center
45+
46+
import matplotlib.pyplot as plt
47+
import numpy as np
48+
49+
x = np.arange(0, 4, 0.05)
50+
y = np.sin(x*np.pi)
51+
52+
fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True)
53+
ax.plot(x, y)
54+
ax.set_xlabel('t [s]')
55+
ax.set_ylabel('S [V]')
56+
ax.set_title('Sine wave')
57+
58+
.. plot::
59+
:include-source:
60+
:align: center
61+
62+
import matplotlib.pyplot as plt
63+
import numpy as np
64+
65+
x = np.arange(0, 4, 0.05)
66+
67+
fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True)
68+
ax.pcolormesh(x, x, np.random.randn(len(x)-1, len(x)-1) )
69+
ax.set_xlabel('t [s]')
70+
ax.set_ylabel('S [V]')
71+
ax.set_title('Sine wave')
72+
73+
74+
Configuration for this demo
75+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
77+
The full ``conf.py`` is
4178

4279
.. literalinclude:: conf.py

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pydata-sphinx-theme>=0.9.0
1+
pydata-sphinx-theme>=0.9.0
2+
matplotlib

mpl_sphinx_theme/mpl_navbar_logo.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{% else %}
1111
<a class="navbar-brand" href="{{ pathto(theme_logo_link) }}">
1212
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="logo">
13-
</a>
13+
</a>
1414
{% endif %}
1515
{% else %}
1616
{% if not theme_logo_link %}
@@ -24,6 +24,7 @@
2424
{% else %}
2525
<a class="navbar-brand" href="{{ pathto(theme_logo_link) }}">
2626
<img src="_static/images/logo2.svg" class="logo" alt="logo">
27-
</a>
27+
</a>
28+
{% endif %}
2829
{% endif %}
29-
{% endif %}
30+

mpl_sphinx_theme/static/css/style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
html[data-theme="light"], html[data-theme="dark"] {
2-
--pst-color-primary: rgb(19, 6, 84);
2+
--pst-color-primary: #11557c;
33
--pst-color-link: rgb(17, 85, 124);
44
--pst-color-link-hover: rgb(0, 60, 99);
55
}
@@ -9,6 +9,7 @@ html[data-theme="light"] {
99
}
1010

1111
html[data-theme="dark"] {
12+
--pst-color-primary: #65baeaff;
1213
--pst-color-text-base: rgb(240, 240, 240);
1314
}
1415

mpl_sphinx_theme/static/images/logo_dark.svg

Lines changed: 556 additions & 0 deletions
Loading

mpl_sphinx_theme/theme.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ stylesheet = css/style.css
44

55
[options]
66
native_site = False
7-
navbar_start = mpl_navbar_logo.html
7+
# navbar_start = mpl_navbar_logo.html
88
navbar_center = mpl_nav_bar.html
9-
navbar_end = mpl_icon_links.html
9+
navbar_end = mpl_icon_links.html, theme-switcher.html
10+
logo = images/logo2.svg

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pydata-sphinx-theme>=0.9.0
1+
pydata-sphinx-theme>=0.9.0
2+
matplotlib

0 commit comments

Comments
 (0)