|
35 | 35 | # %%
|
36 | 36 | # By default, `~.Axes.plot` joins data points with a solid straight line, as
|
37 | 37 | # shown in the jagged nature of the plot above. We can style that line,
|
38 |
| -# with dashes or plot the data with symbols, or both, as below. |
| 38 | +# with dashes, plot the data with symbols, or both styles, as demonstrated below. |
39 | 39 |
|
40 | 40 | fig, axs = plt.subplots(3, 1, sharex=True)
|
41 | 41 | ax = axs[0]
|
|
48 | 48 | ax.set_xlabel('x')
|
49 | 49 |
|
50 | 50 | # %%
|
51 |
| -# It is possible to plot multiple datasets at once against one ``x`` array |
52 |
| -# if the shape of ``Y`` matches. Here note that ``Y`` has shape ``(30,3)`` |
53 |
| -# so the length of each column is the same as the length of ``x``. |
54 |
| -# Each column of data in ``Y`` gets a different color following the |
| 51 | +# Multiple datasets can be plotted simultaneously against a single ``x`` array |
| 52 | +# if the shape of ``Y`` is compatible. In this example, ``Y`` has the shape ``(30, 3)``, |
| 53 | +# meaning each column has the same length as ``x``. |
| 54 | +# Each column in ``Y`` is assigned a different color according to the |
55 | 55 | # default :ref:`color cycle <color_cycle>`. A legend for each column in
|
56 |
| -# ``Y`` is created by passing a **label** with a list of column names: |
| 56 | +# ``Y`` is generated by providing a **label** with a list of column names: |
57 | 57 |
|
58 | 58 | Y = np.arange(30*3).reshape(3, 30).T
|
59 | 59 | fig, ax = plt.subplots(figsize=(5, 3))
|
|
63 | 63 |
|
64 | 64 | # %%
|
65 | 65 | # fill_between, fill_betweenx, and stackplot
|
66 |
| -# ------------------------------------------ |
| 66 | +# ----------------------------------------- |
67 | 67 | #
|
68 | 68 | # The `~.Axes.fill_between` method is useful to indicate a confidence interval
|
69 | 69 | # around a line plot. In this example, the confidence interval is imagined to
|
|
153 | 153 |
|
154 | 154 | # %%
|
155 | 155 | #
|
156 |
| -# `~.Axes.errorbar` inherits from `~.Axes.plot`, so the same format strings can |
157 |
| -# be used to control the marker's appearance. Errorbar appearance is controlled |
158 |
| -# by keyword arguments such as *ecolor* for the color of the error bar lines, |
159 |
| -# **capsize** for the length of the error bar caps, and *elinewidth* for the |
160 |
| -# thickness of the error bar lines. The error bars can also be asymmetric if |
161 |
| -# *yerr* or *xerr* are 2D arrays. |
| 156 | +# `~.Axes.errorbar` inherits from `~.Axes.plot`, allowing the use of the same |
| 157 | +# format to control the marker's appearance. The appearance of error bars is |
| 158 | +# controlled by keyword arguments such as *ecolor* for the color of the error |
| 159 | +# bar lines, **capsize** for the length of the error bar caps, and *elinewidth* |
| 160 | +# for the thickness of the error bar lines. Error bars can also be asymmetric |
| 161 | +# if *yerr* or *xerr* are provided as 2D arrays. |
162 | 162 |
|
163 | 163 | fig, ax = plt.subplots()
|
164 | 164 | ax.errorbar(x, y, yerr=[erry, 2*erry], xerr=[errx, 2*errx], fmt='o',
|
|
171 | 171 | # scatter
|
172 | 172 | # -------
|
173 | 173 | #
|
174 |
| -# The `~.Axes.scatter` method is similar to `~.Axes.plot` in that it will plot two |
175 |
| -# arrays of data against each other, but differs in that |
| 174 | +# The `~.Axes.scatter` method is similar to `~.Axes.plot` in that it plots two |
| 175 | +# arrays of data against each other, but differs in the following ways: |
176 | 176 | #
|
177 |
| -# * there is no option to connect markers with lines |
178 |
| -# * the size and color of markers can vary according to the value of other data arrays. |
| 177 | +# * there is no option to connect markers with lines, |
| 178 | +# * the size and color of markers can vary according to the values of other data arrays. |
179 | 179 | #
|
180 |
| -# This example shows how to plot a scatter plot with varying point sizes using |
| 180 | +# This example demonstrates how to create a scatter plot with varying point sizes using |
181 | 181 | # the *s* keyword and and colors using the *c* keyword.
|
182 | 182 |
|
183 | 183 | y = np.sin(x)
|
|
194 | 194 | fig.colorbar(scatter, label="Value of sin(x)")
|
195 | 195 |
|
196 | 196 | #######################################################################################
|
197 |
| -# We can change the marker (see :mod:`matplotlib.markers` for a full list), but each |
198 |
| -# call to scatter can only accept one *marker*. If it is desired to code data by |
199 |
| -# marker shape, then make multiple calls to `~.Axes.scatter` |
| 197 | +# The marker style can be changed (see :mod:`matplotlib.markers` for a full |
| 198 | +# list), but each call to `~.Axes.scatter` can only accept one *marker* type. |
| 199 | +# To code data by different marker shapes, make multiple calls to |
| 200 | +# `~.Axes.scatter`. |
200 | 201 |
|
201 | 202 | y2 = np.cos(x)
|
202 | 203 | colors2 = y2
|
|
226 | 227 | # ---------------------
|
227 | 228 | #
|
228 | 229 | # `~.Axes.bar`, `~.Axes.stairs`, and `~.Axes.stem` are useful for plotting data
|
229 |
| -# that deviates from a zero or mean value, and are often used to plot |
| 230 | +# that deviates from a zero or mean value. These methods are often used to plot |
230 | 231 | # histograms.
|
231 | 232 |
|
232 | 233 | x = x[::2]
|
|
246 | 247 | ax.set_ylabel('sin(x)')
|
247 | 248 |
|
248 | 249 | # %%
|
249 |
| -# `~.Axes.bar` does not automatically calculate a *width* for the bars, so you |
250 |
| -# typically have to calculate it yourself to get the correct spacing. *width* |
251 |
| -# can also be an array with the same length as *x* to specify the width of each |
| 250 | +# `~.Axes.bar` does not automatically calculate the *width* of the bars, so it |
| 251 | +# typically needs to be calculated manually to achieve the correct spacing. The *width* |
| 252 | +# can also be specified as an array with the same length as *x* to set the width of each |
252 | 253 | # bar individually.
|
253 | 254 |
|
254 | 255 | fig, ax = plt.subplots()
|
|
262 | 263 | #
|
263 | 264 | # `~.Axes.step` and `~.Axes.stairs` are similar to `~.Axes.plot` but plot a
|
264 | 265 | # step between each data point. They accept differently shaped data depending
|
265 |
| -# on your use case. |
| 266 | +# on the use case. |
266 | 267 | #
|
267 |
| -# `~.Axes.step` is useful for plotting steps, and accepts the same data shape |
268 |
| -# as `~.Axes.plot`. |
| 268 | +# `~.Axes.step` particularly useful as it accepts the same data shape as |
| 269 | +# `~.Axes.plot`. |
269 | 270 |
|
270 | 271 | fig, ax = plt.subplots()
|
271 | 272 |
|
|
275 | 276 | ax.set_title('step')
|
276 | 277 |
|
277 | 278 | # %%
|
278 |
| -# Note that we can center the steps on the data in different ways |
279 |
| -# using the **where** keyword. The default is **where='pre'** which |
280 |
| -# mea
C034
ns the step extends to the left of the data point. **where='mid'** |
281 |
| -# means the step extends half way to the next data point, and **where='post'** |
282 |
| -# means the step extends to the right of the data point: |
| 279 | + |
| 280 | +# The steps can be centered on the data in different ways using the **where** |
| 281 | +# keyword. The default is **where='pre'**, which means the step extends to the |
| 282 | +# left of the data point. **where='mid'** means the step extends halfway to the |
| 283 | +# next data point, and **where='post'** means the step extends to the right of |
| 284 | +# the data point: |
283 | 285 |
|
284 | 286 | fig, axs = plt.subplots(3, 1, sharex=True, sharey=True, figsize=(4.5, 5))
|
285 | 287 |
|
|
295 | 297 |
|
296 | 298 | # %%
|
297 | 299 | #
|
298 |
| -# `~.Axes.stairs` is useful for plotting histograms, and specifies the edges of steps |
299 |
| -# rather than the centers. This is particularly useful for plotting histograms, and can |
300 |
| -# be used with the result from `~numpy.histogram`. |
| 300 | +# `~.Axes.stairs` is useful for plotting histograms, and specifies the edges of |
| 301 | +# steps rather than the centers, so can directly be used with the result from |
| 302 | +# `~numpy.histogram`. |
301 | 303 |
|
302 | 304 | data = rng.normal(size=1000)
|
303 | 305 | hist, bin_edges = np.histogram(data, bins=np.arange(-4, 4, 0.2), density=True)
|
|
0 commit comments