Skip to content

Commit 6a80fc4

Browse files
authored
Merge branch 'main' into pie-example
2 parents cce3b64 + 9c48e4b commit 6a80fc4

File tree

282 files changed

+986
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+986
-935
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ per-file-ignores =
8484
tutorials/introductory/quick_start.py: E703
8585
tutorials/introductory/animation_tutorial.py: E501
8686
tutorials/text/annotations.py: E402, E501
87+
tutorials/text/mathtext.py: E501
8788
tutorials/text/text_intro.py: E402
8889
tutorials/text/text_props.py: E501
8990
tutorials/text/usetex.py: E501

doc/devel/documenting_mpl.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,15 @@ to create a gallery of images in the :file:`/doc/gallery` and
812812
:file:`/doc/tutorials` directories respectively. To exclude an example
813813
from having an plot generated insert "sgskip" somewhere in the filename.
814814

815+
816+
Formatting the example
817+
----------------------
818+
815819
The format of these files is relatively straightforward. Properly
816820
formatted comment blocks are treated as ReST_ text, the code is
817-
displayed, and figures are put into the built page.
821+
displayed, and figures are put into the built page. Matplotlib uses the
822+
``# %%`` section separator so that IDEs will identify "code cells" to make
823+
it easy to re-run sub-sections of the example.
818824

819825
For instance the example :doc:`/gallery/lines_bars_and_markers/simple_plot`
820826
example is generated from
@@ -853,7 +859,7 @@ Tutorials are made with the exact same mechanism, except they are longer, and
853859
typically have more than one comment block (i.e.
854860
:doc:`/tutorials/introductory/quick_start`). The first comment block
855861
can be the same as the example above. Subsequent blocks of ReST text
856-
are delimited by a line of ``###`` characters:
862+
are delimited by the line ``# %%`` :
857863

858864
.. code-block:: python
859865
@@ -868,7 +874,7 @@ are delimited by a line of ``###`` characters:
868874
ax.grid()
869875
plt.show()
870876
871-
##########################################################################
877+
# %%
872878
# Second plot
873879
# ===========
874880
#
@@ -887,7 +893,7 @@ bottom as follows
887893

888894
.. code-block:: python
889895
890-
###############################################################################
896+
# %%
891897
#
892898
# .. admonition:: References
893899
#

doc/sphinxext/gallery_order.py

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,52 @@
66
from sphinx_gallery.sorting import ExplicitOrder
77

88
# Gallery sections shall be displayed in the following order.
9-
# Non-matching sections are inserted at UNSORTED
10-
explicit_order_folders = [
11-
'../examples/lines_bars_and_markers',
12-
'../examples/images_contours_and_fields',
13-
'../examples/subplots_axes_and_figures',
14-
'../examples/statistics',
15-
'../examples/pie_and_polar_charts',
16-
'../examples/text_labels_and_annotations',
17-
'../examples/pyplots',
18-
'../examples/color',
19-
'../examples/shapes_and_collections',
20-
'../examples/style_sheets',
21-
'../examples/axes_grid1',
22-
'../examples/axisartist',
23-
'../examples/showcase',
24-
'../tutorials/introductory',
25-
'../tutorials/intermediate',
26-
'../tutorials/advanced',
27-
'../plot_types/basic',
28-
'../plot_types/arrays',
29-
'../plot_types/stats',
30-
'../plot_types/unstructured',
31-
'../plot_types/3D',
32-
'UNSORTED',
33-
'../examples/userdemo',
34-
'../tutorials/provisional',
35-
]
9+
# Non-matching sections are inserted at the unsorted position
10+
11+
UNSORTED = "unsorted"
12+
13+
examples_order = [
14+
'../examples/lines_bars_and_markers',
15+
'../examples/images_contours_and_fields',
16+
'../examples/subplots_axes_and_figures',
17+
'../examples/statistics',
18+
'../examples/pie_and_polar_charts',
19+
'../examples/text_labels_and_annotations',
20+
'../examples/pyplots',
21+
'../examples/color',
22+
'../examples/shapes_and_collections',
23+
'../examples/style_sheets',
24+
'../examples/axes_grid1',
25+
'../examples/axisartist',
26+
'../examples/showcase',
27+
UNSORTED,
28+
'../examples/userdemo',
29+
]
30+
31+
tutorials_order = [
32+
'../tutorials/introductory',
33+
'../tutorials/intermediate',
34+
'../tutorials/advanced',
35+
UNSORTED,
36+
'../tutorials/provisional'
37+
]
38+
39+
plot_types_order = [
40+
'../plot_types/basic',
41+
'../plot_types/arrays',
42+
'../plot_types/stats',
43+
'../plot_types/unstructured',
44+
'../plot_types/3D',
45+
UNSORTED
46+
]
47+
48+
folder_lists = [examples_order, tutorials_order, plot_types_order]
49+
50+
explicit_order_folders = [fd for folders in folder_lists
51+
for fd in folders[:folders.index(UNSORTED)]]
52+
explicit_order_folders.append(UNSORTED)
53+
explicit_order_folders.extend([fd for folders in folder_lists
54+
for fd in folders[folders.index(UNSORTED):]])
3655

3756

3857
class MplExplicitOrder(ExplicitOrder):
@@ -42,7 +61,7 @@ def __call__(self, item):
4261
if item in self.ordered_list:
4362
return f"{self.ordered_list.index(item):04d}"
4463
else:
45-
return f"{self.ordered_list.index('UNSORTED'):04d}{item}"
64+
return f"{self.ordered_list.index(UNSORTED):04d}{item}"
4665

4766
# Subsection order:
4867
# Subsections are ordered by filename, unless they appear in the following
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pad_inches="layout" for savefig
2+
-------------------------------
3+
4+
When using constrained or compressed layout,
5+
6+
.. code-block:: python
7+
8+
savefig(filename, bbox_inches="tight", pad_inches="layout")
9+
10+
will now use the padding sizes defined on the layout engine.

examples/animation/animated_histogram.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
data = np.random.randn(1000)
2222
n, _ = np.histogram(data, HIST_BINS)
2323

24-
###############################################################################
24+
# %%
2525
# To animate the histogram, we need an ``animate`` function, which generates
2626
# a random set of numbers and updates the heights of rectangles. We utilize a
2727
# python closure to track an instance of `.BarContainer` whose `.Rectangle`
@@ -39,7 +39,7 @@ def animate(frame_number):
3939
return bar_container.patches
4040
return animate
4141

42-
###############################################################################
42+
# %%
4343
# Using :func:`~matplotlib.pyplot.hist` allows us to get an instance of
4444
# `.BarContainer`, which is a collection of `.Rectangle` instances. Calling
4545
# ``prepare_animation`` will define ``animate`` function working with supplied

examples/animation/multiple_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def animate(i):
7070

7171
plt.show()
7272

73-
#############################################################################
73+
# %%
7474
#
7575
# .. admonition:: References
7676
#

examples/axes_grid1/demo_axes_hbox_divider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
plt.show()
3535

36-
###############################################################################
36+
# %%
3737
# Using a `.VBoxDivider` to arrange subplots.
3838
#
3939
# Note that both axes' location are adjusted so that they have

examples/axes_grid1/demo_fixed_size_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from mpl_toolkits.axes_grid1 import Divider, Size
1010

11-
###############################################################################
11+
# %%
1212

1313

1414
fig = plt.figure(figsize=(6, 6))
@@ -26,7 +26,7 @@
2626

2727
ax.plot([1, 2, 3])
2828

29-
###############################################################################
29+
# %%
3030

3131

3232
fig = plt.figure(figsize=(6, 6))

examples/axes_grid1/inset_locator_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
"""
77

8-
###############################################################################
8+
# %%
99
# The `.inset_locator`'s `~.inset_locator.inset_axes` allows
1010
# easily placing insets in the corners of the axes by specifying a width and
1111
# height and optionally a location (loc) that accepts locations as codes,
@@ -43,7 +43,7 @@
4343
plt.show()
4444

4545

46-
###############################################################################
46+
# %%
4747
# The parameters *bbox_to_anchor* and *bbox_transform* can be used for a more
4848
# fine-grained control over the inset position and size or even to position
4949
# the inset at completely arbitrary positions.
@@ -100,7 +100,7 @@
100100
plt.show()
101101

102102

103-
###############################################################################
103+
# %%
104104
# In the above the axes transform together with 4-tuple bounding boxes has been
105105
# used as it mostly is useful to specify an inset relative to the axes it is
106106
# an inset to. However, other use cases are equally possible. The following

examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
make_axes_area_auto_adjustable(ax)
1919

20-
###############################################################################
20+
# %%
2121

2222
fig = plt.figure()
2323
ax1 = fig.add_axes([0, 0, 1, 0.5])
@@ -31,7 +31,7 @@
3131
make_axes_area_auto_adjustable(ax1, pad=0.1, use_axes=[ax1, ax2])
3232
make_axes_area_auto_adjustable(ax2, pad=0.1, use_axes=[ax1, ax2])
3333

34-
###############################################################################
34+
# %%
3535

3636
fig = plt.figure()
3737
ax1 = fig.add_axes([0, 0, 1, 1])

examples/axes_grid1/scatter_hist_locatable_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
plt.show()
6565

66-
#############################################################################
66+
# %%
6767
#
6868
# .. admonition:: References
6969
#

examples/axes_grid1/simple_axes_divider1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def label_axes(ax, text):
1818
left=False, labelleft=False)
1919

2020

21-
##############################################################################
21+
# %%
2222
# Fixed axes sizes; fixed paddings.
2323

2424
fig = plt.figure(figsize=(6, 6))
@@ -42,7 +42,7 @@ def label_axes(ax, text):
4242
ax4 = fig.add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
4343
label_axes(ax4, "nx=2, nx1=4, ny=0")
4444

45-
##############################################################################
45+
# %%
4646
# Axes sizes that scale with the figure size; fixed paddings.
4747

4848
fig = plt.figure(figsize=(6, 6))

examples/axisartist/demo_floating_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def setup_axes3(fig, rect):
145145
return ax1, aux_ax
146146

147147

148-
##########################################################
148+
# %%
149149
fig = plt.figure(figsize=(8, 4))
150150
fig.subplots_adjust(wspace=0.3, left=0.05, right=0.95)
151151

examples/color/color_by_yvalue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ax.plot(t, smiddle, t, slower, t, supper)
2323
plt.show()
2424

25-
#############################################################################
25+
# %%
2626
#
2727
# .. admonition:: References
2828
#

examples/color/color_cycle_default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
plt.show()
4242

43-
#############################################################################
43+
# %%
4444
#
4545
# .. admonition:: References
4646
#

examples/color/color_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
plt.show()
6363

64-
#############################################################################
64+
# %%
6565
#
6666
# .. admonition:: References
6767
#

examples/color/colorbar_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
cbar.minorticks_on()
4646
plt.show()
4747

48-
#############################################################################
48+
# %%
4949
#
5050
# .. admonition:: References
5151
#

examples/color/colormap_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def plot_color_gradients(cmap_category, cmap_list):
6868
plot_color_gradients(cmap_category, cmap_list)
6969

7070

71-
###############################################################################
71+
# %%
7272
# .. _reverse-cmap:
7373
#
7474
# Reversed colormaps
@@ -83,7 +83,7 @@ def plot_color_gradients(cmap_category, cmap_list):
8383
# The built-in reversed colormaps are generated using `.Colormap.reversed`.
8484
# For an example, see :ref:`reversing-colormap`
8585

86-
#############################################################################
86+
# %%
8787
#
8888
# .. admonition:: References
8989
#

examples/color/custom_cmap.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
Z = np.cos(X) * np.sin(Y) * 10
109109

110110

111-
###############################################################################
111+
# %%
112112
# Colormaps from a list
113113
# ---------------------
114114

@@ -126,7 +126,7 @@
126126
fig.colorbar(im, ax=ax)
127127

128128

129-
###############################################################################
129+
# %%
130130
# Custom colormaps
131131
# ----------------
132132

@@ -202,14 +202,14 @@
202202
}
203203

204204

205-
###############################################################################
205+
# %%
206206
# Now we will use this example to illustrate 2 ways of
207207
# handling custom colormaps.
208208
# First, the most direct and explicit:
209209

210210
blue_red1 = LinearSegmentedColormap('BlueRed1', cdict1)
211211

212-
###############################################################################
212+
# %%
213213
# Second, create the map explicitly and register it.
214214
# Like the first method, this method works with any kind
215215
# of Colormap, not just
@@ -219,7 +219,7 @@
219219
mpl.colormaps.register(LinearSegmentedColormap('BlueRed3', cdict3))
220220
mpl.colormaps.register(LinearSegmentedColormap('BlueRedAlpha', cdict4))
221221

222-
###############################################################################
222+
# %%
223223
# Make the figure, with 4 subplots:
224224

225225
fig, axs = plt.subplots(2, 2, figsize=(6, 9))
@@ -264,7 +264,7 @@
264264

265265
plt.show()
266266

267-
#############################################################################
267+
# %%
268268
#
269269
# .. admonition:: References
270270
#

0 commit comments

Comments
 (0)