Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57b315e

Browse files
committed
DOC: Add overview of axes creation methods
Closes #17376. There might still be room for further improvements, be it description or formatting. But I would like to leave that for later. The main goal is to get a first version of this in soon.
1 parent f7a8cab commit 57b315e

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#################################
2+
Overview of Axes creation methods
3+
#################################
4+
5+
Depending on the use case, different methods for creating an Axes are most useful.
6+
The following diagram gives an overview by characterizing the desired Axes.
7+
8+
Additionally, most of the methods come in two flavors: A `pyplot` function and a
9+
method on a `.Figure` or `~.axes.Axes`.
10+
11+
``plt.subplots()`` and ``plt.subplot_mosaic()`` return a Figure and one or more Axes.
12+
They are the most common stating points for a Matplotlib plot. All other methods
13+
only return an Axes.
14+
15+
.. graphviz::
16+
17+
digraph {
18+
node[shape=diamond, width=2.7, height=0.8]
19+
q_fullsize; q_simple_grid; q_complex_grid; q_inset; q_twin;
20+
node[shape=none, margin=0]
21+
full_size;
22+
23+
legend [label=<
24+
<FONT FACE="helvetica-bold"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5">
25+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="200">pyplot functions</TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="200">Figure/Axes methods</TD></TR>
26+
<TR><TD BGCOLOR="white" ALIGN="left" WIDTH="200"><FONT FACE="helvetica" COLOR="gray50">less used variants</FONT></TD></TR>
27+
</TABLE></FONT>>]
28+
29+
30+
q_fullsize [label="full size?"]
31+
full_size [label=<
32+
<FONT FACE="helvetica"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5">
33+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="200">plt.subplots()</TD><TD BGCOLOR="gray90" ALIGN="left">Figure.subplots()</TD></TR>
34+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="200"><FONT COLOR="gray50">plt.subplot()</FONT></TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="200"><FONT COLOR="gray50">Figure.add_subplot()</FONT></TD></TR>
35+
</TABLE></FONT>>]
36+
q_simple_grid [label="simple grid?"]
37+
simple_grid [label=<
38+
<FONT FACE="helvetica"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5">
39+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left">plt.subplots(n, m)</TD><TD BGCOLOR="gray90" ALIGN="left">Figure.subplots(n, m)</TD></TR>
40+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="200"><FONT COLOR="gray50">plt.subplot(n, m, k)</FONT></TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="200"><FONT COLOR="gray50">Figure.add_subplot(n, m, k)</FONT></TD></TR>
41+
</TABLE></FONT>>]
42+
q_complex_grid [label="complex grid?"]
43+
complex_grid [label=<
44+
<FONT FACE="helvetica"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5">
45+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="200">plt.subplot_mosaic()</TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="200">Figure.subplot_mosaic()</TD></TR>
46+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left"><FONT COLOR="gray50">plt.subplot2grid()</FONT></TD><TD BGCOLOR="gray90" ALIGN="left"><FONT COLOR="gray50">GridSpec.subplots()</FONT></TD></TR>
47+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left"><FONT COLOR="gray50">plt.subplots(gridspec_kw)</FONT></TD><TD BGCOLOR="gray90" ALIGN="left"><FONT COLOR="gray50">Figure.subplots(gridspec_kw)</FONT></TD></TR>
48+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left"><FONT COLOR="gray50">plt.subplot(subplotspec)</FONT></TD><TD BGCOLOR="gray90" ALIGN="left"><FONT COLOR="gray50">Figure.subplot(subplotspec)</FONT></TD></TR>
49+
</TABLE></FONT>>]
50+
q_inset [label="inset?"]
51+
inset [label=<
52+
<FONT FACE="helvetica"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5" ALIGN="left">
53+
<TR><TD BGCOLOR="white" ALIGN="left" WIDTH="200"></TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="200">Axes.inset_axes()</TD></TR>
54+
</TABLE></FONT>>]
55+
q_twin [label="twin?"]
56+
twin [label=<
57+
<FONT FACE="helvetica"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5">
58+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="200">plt.twinx()</TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="200">Axes.twinx()</TD></TR>
59+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left">plt.twiny()</TD><TD BGCOLOR="gray90" ALIGN="left">Axes.twiny()</TD></TR>
60+
</TABLE></FONT>>]
61+
axes [label=<
62+
<FONT FACE="helvetica"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="5">
63+
<TR><TD BGCOLOR="#C5E5F7" ALIGN="left" WIDTH="150">plt.axes()</TD><TD BGCOLOR="gray90" ALIGN="left" WIDTH="150">Figure.add_axes()</TD></TR>
64+
</TABLE></FONT>>]
65+
66+
legend -> full_size [ style = invis ];
67+
68+
q_fullsize -> q_simple_grid [ label = "No" ];
69+
q_simple_grid -> q_complex_grid [label = "No" ];
70+
q_fullsize -> full_size [ label = "Yes" ];
71+
q_simple_grid -> simple_grid[ label = "Yes" ];
72+
q_complex_grid -> complex_grid [label = "Yes"];
73+
q_complex_grid -> q_inset [label = "No"];
74+
q_inset -> inset[label="Yes"];
75+
q_inset -> q_twin [label="No"]
76+
q_twin -> twin[label="Yes"]
77+
q_twin -> axes[label="No"]
78+
79+
{
80+
rank=same;
81+
q_fullsize full_size
82+
}
83+
{
84+
rank=same;
85+
q_simple_grid simple_grid
86+
}
87+
{
88+
rank=same;
89+
q_complex_grid complex_grid
90+
}
91+
{
92+
rank=same;
93+
q_inset inset
94+
}
95+
{
96+
rank=same;
97+
q_twin twin
98+
}
99+
}

galleries/users_explain/axes/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ annotations like x- and y-labels, titles, and legends.
2929
:maxdepth: 2
3030

3131
axes_intro
32+
axes_creation
33+
3234

3335
.. toctree::
3436
:maxdepth: 1

0 commit comments

Comments
 (0)