8000 Merge pull request #26105 from jklymak/doc-user-guide-cards · matplotlib/matplotlib@704c7d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 704c7d8

Browse files
authored
Merge pull request #26105 from jklymak/doc-user-guide-cards
Doc user guide cards
2 parents e9e3579 + d29f0d5 commit 704c7d8

File tree

5 files changed

+133
-25
lines changed

5 files changed

+133
-25
lines changed

doc/_static/image-rotator.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// accessible JavaScript tab switcher
2+
// modified from https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Tab_Role
3+
4+
function getRandomInt(max) {
5+
return Math.floor(Math.random() * max);
6+
}
7+
8+
var images_rotate = [
9+
{"image": "sphx_glr_plot_001_2_00x.png", "caption": "plot(x, y)", "link": "plot_types/basic/plot.html"},
10+
{"image": "sphx_glr_step_001_2_00x.png", "caption": "step(x, y)", "link": "plot_types/basic/step.html"},
11+
{"image": "sphx_glr_scatter_plot_001_2_00x.png", "caption": "scatter(x, y)", "link": "plot_types/basic/scatter_plot.html"},
12+
{"image": "sphx_glr_pcolormesh_001_2_00x.png", "caption": "pcolormesh(X, Y, Z)", "link": "plot_types/arrays/pcolormesh.html"},
13+
{"image": "sphx_glr_contourf_001_2_00x.png", "caption": "contourf(X, Y, Z)", "link": "plot_types/arrays/contourf.html"},
14+
{"image": "sphx_glr_step_001_2_00x.png", "caption": "step(x, y)", "link": "plot_types/basic/step.html"},
15+
{"image": "sphx_glr_streamplot_001_2_00x.png", "caption": "streamplot(X, Y, U, V)", "link": "plot_types/arrays/streamplot.html"},
16+
{"image": "sphx_glr_bar_001_2_00x.png", "caption": "bar(x, height) / barh(y, width)", "link": "plot_types/basic/bar.html"},
17+
{"image": "sphx_glr_hist_plot_001_2_00x.png", "caption": "hist(x)", "link": "plot_types/stats/hist_plot.html"},
18+
{"image": "sphx_glr_imshow_001_2_00x.png", "caption": "imshow(Z)", "link": "plot_types/arrays/imshow.html"},
19+
];
20+
21+
document.addEventListener("DOMContentLoaded", function(event) {
22+
///////////////////////////////////////
23+
// rotate images in images-rotate directory:
24+
var ind = getRandomInt(images_rotate.length);
25+
var info = images_rotate[ind];
26+
var img_src = "../_images/" + info.image;
27+
var caption = info.caption;
28+
var link = "https://matplotlib.org/stable/" + info.link;
29+
var html = '<a href="' + link + '">' +
30+
'<img class="imrot-img" src="' + img_src + '" aria-labelledby="sample-plot-caption"/>' +
31+
'<div class="imrot-cap" id="sample-plot-caption">' + caption + '</div>' +
32+
'</a>';
33+
document.getElementById('image_rotator').innerHTML = html;
34+
35+
ind = getRandomInt(images_rotate.length);
36+
info = images_rotate[ind];
37+
img_src = "../_images/" + info.image;
38+
caption = info.caption;
39+
link = "https://matplotlib.org/stable/" + info.link;
40+
html = '<a href="' + link + '">' +
41+
'<img class="imrot-img" src="' + img_src + '" aria-labelledby="sample-plot-caption"/>' +
42+
'<div class="imrot-cap" id="sample-plot-caption">' + caption + '</div>' +
43+
'</a>';
44+
document.getElementById('image_rotator2').innerHTML = html;
45+
46+
});

doc/_static/mpl.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,16 @@ div.wide-table table th.stub {
120120
left: 0;
121121
position: sticky;
122122
}
123+
124+
.imrot-img {
125+
display: flex;
126+
margin: auto;
127+
max-width:15em;
128+
align-self: center;
129+
}
130+
131+
.imrot-cap {
132+
text-align: center;
133+
font-style: italic;
134+
font-size: large;
135+
}

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,4 +772,5 @@ def setup(app):
772772
bld_type = 'rel'
773773
app.add_config_value('skip_sub_dirs', 0, '')
774774
app.add_config_value('releaselevel', bld_type, 'env')
775+
app.add_js_file('image-rotator.js')
775776
app.connect('html-page-context', add_html_cache_busting, priority=1000)

doc/users/index.rst

Lines changed: 71 additions & 25 deletions
2364
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,86 @@
22

33
.. redirect-from:: /contents
44

5-
65
##########
76
User guide
87
##########
98

10-
General
11-
#######
9+
.. grid:: 1 1 2 2
10+
11+
.. grid-item-card:: Starting information
12+
:padding: 2
13+
14+
.. plot::
15+
16+
rng = np.random.default_rng(seed=19680808)
17+
x = np.linspace(0, 4, 1000) # Sample data.
18+
y = rng.normal(size=len(x)) * 1.5 + x**2 + np.cumsum(rng.normal(size=len(x))) / 6
19+
x = x[::10]
20+
y = y[::10]
21+
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
22+
23+
ax.plot(x, x**2, label='underlying data', linewidth=4, alpha=0.6, color='k')
24+
ax.scatter(x, y, s=13 * rng.random(size=len(x)), c=rng.normal(size=len(x)),
25+
label='noisy data')
26+
# p = np.polyfit(x, y, deg=1)
27+
# print(p)
28+
p = np.array([ 3.81283983, -2.00111268])
29+
out = np.polyval(p, x)
30+
ax.plot(x, out, label='linear fit') # Plot some data on the axes.
31+
# p = np.polyfit(x, y, deg=2)
32+
# print(p)
33+
p = np.array([ 1.18076933, -0.86768725, 1.05989268])
34+
out = np.polyval(p, x)
35+
ax.plot(x, out, label='quadratic fit')
36+
ax.set_xlabel('x label')
37+
ax.set_ylabel('y label')
38+
ax.set_title("Simple plot")
39+
ax.legend()
40+
41+
42+
.. toctree::
43+
:maxdepth: 1
44+
45+
getting_started/index.rst
46+
installing/index.rst
47+
FAQ: How-to and troubleshooting <faq/index.rst>
48+
49+
.. grid-item-card:: Users guide
50+
:padding: 2
51+
52+
.. toctree::
53+
:maxdepth: 2
54+
55+
explain/index.rst
56+
57+
.. grid-item-card:: Tutorials and examples
58+
:padding: 2
59+
60+
.. toctree::
61+
:maxdepth: 1
62+
63+
../plot_types/index.rst
64+
../gallery/index.rst
65+
../tutorials/index.rst
66+
resources/index.rst
67+
1268

13-
.. toctree::
14-
:maxdepth: 2
69+
.. raw:: html
1570

16-
getting_started/index.rst
17-
installing/index.rst
18-
explain/index.rst
19-
faq/index.rst
20-
resources/index.rst
71+
<div class="grid__intro" id="image_rotator"></div>
2172

22-
Tutorials and examples
23-
######################
2473

25-
.. toctree::
26-
:maxdepth: 1
74+
.. grid-item-card:: More information
75+
:padding: 2
2776

28-
../plot_types/index.rst
29-
../tutorials/index.rst
30-
../gallery/index.rst
77+
.. toctree::
78+
:maxdepth: 1
3179

32-
Reference
33-
#########
80+
Reference <../api/index.rst>
81+
Contribute <../devel/index.rst>
82+
Releases <release_notes.rst>
3483

35-
.. toctree::
36-
:maxdepth: 2
84+
.. toctree::
85+
:maxdepth: 2
3786

38-
../api/index.rst
39-
../devel/index.rst
40-
project/index.rst
41-
release_notes.rst
87+
project/index.rst

galleries/users_explain/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
.. redirect-from:: /users/explain
55

6+
7+
68
Using Matplotlib
79
----------------
810

0 commit comments

Comments
 (0)
0