File size: 3,178 Bytes
714e7c4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | ##########
Some plots
##########
Plot 1 does not use context:
.. plot::
plt.plot(range(10))
a = 10
Plot 2 doesn't use context either; has length 6:
.. plot::
plt.plot(range(6))
Plot 3 has length 4, and uses doctest syntax:
.. plot::
:format: doctest
This is a doctest...
>>> plt.plot(range(4))
... isn't it?
Plot 4 shows that a new block with context does not see the variable defined
in the no-context block:
.. plot::
:context:
assert 'a' not in globals()
Plot 5 defines ``a`` in a context block:
.. plot::
:context:
plt.plot(range(6))
a = 10
Plot 6 shows that a block with context sees the new variable. It also uses
``:nofigs:``:
.. plot::
:context:
:nofigs:
assert a == 10
b = 4
Plot 7 uses a variable previously defined in previous ``nofigs`` context. It
also closes any previous figures to create a fresh figure:
.. plot::
:context: close-figs
assert b == 4
plt.plot(range(b))
Plot 8 shows that a non-context block still doesn't have ``a``:
.. plot::
:nofigs:
assert 'a' not in globals()
Plot 9 has a context block, and does have ``a``:
.. plot::
:context:
:nofigs:
assert a == 10
Plot 10 resets context, and ``a`` has gone again:
.. plot::
:context: reset
:nofigs:
assert 'a' not in globals()
c = 10
Plot 11 continues the context, we have the new value, but not the old:
.. plot::
:context:
assert c == 10
assert 'a' not in globals()
plt.plot(range(c))
Plot 12 opens a new figure. By default the directive will plot both the first
and the second figure:
.. plot::
:context:
plt.figure()
plt.plot(range(6))
Plot 13 shows ``close-figs`` in action. ``close-figs`` closes all figures
previous to this plot directive, so we get always plot the figure we create in
the directive:
.. plot::
:context: close-figs
plt.figure()
plt.plot(range(4))
Plot 14 uses ``include-source``:
.. plot::
:include-source:
# Only a comment
Plot 15 uses an external file with the plot commands and a caption:
.. plot:: range4.py
This is the caption for plot 15.
Plot 16 uses a specific function in a file with plot commands:
.. plot:: range6.py range6
Plot 17 gets a caption specified by the :caption: option:
.. plot::
:caption: Plot 17 uses the caption option.
plt.figure()
plt.plot(range(6))
Plot 18 uses an external file with the plot commands and a caption
using the :caption: option:
.. plot:: range4.py
:caption: This is the caption for plot 18.
Plot 19 uses shows that the "plot-directive" class is still appended, even if
we request other custom classes:
.. plot:: range4.py
:class: my-class my-other-class
Should also have a caption.
Plot 20 shows that the default template correctly prints the multi-image
scenario:
.. plot::
:caption: This caption applies to both plots.
plt.figure()
plt.plot(range(6))
plt.figure()
plt.plot(range(4))
Plot 21 is generated via an include directive:
.. include:: included_plot_21.rst
Plot 22 uses a different specific function in a file with plot commands:
.. plot:: range6.py range10
|