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

Skip to content

Commit b56734e

Browse files
authored
Merge pull request #11524 from tacaswell/doc_more_backports
Doc more backports
2 parents 7d1e817 + 3e784a8 commit b56734e

Some content is hidden

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

65 files changed

+1560
-419
lines changed

examples/color/color_by_yvalue.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,17 @@
2222
fig, ax = plt.subplots()
2323
ax.plot(t, smiddle, t, slower, t, supper)
2424
plt.show()
25+
26+
#############################################################################
27+
#
28+
# ------------
29+
#
30+
# References
31+
# """"""""""
32+
#
33+
# The use of the following functions, methods, classes and modules is shown
34+
# in this example:
35+
36+
import matplotlib
37+
matplotlib.axes.Axes.plot
38+
matplotlib.pyplot.plot

examples/color/color_cycle_default.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Colors in the default property cycle
44
====================================
55
6-
Display the colors from the default prop_cycle.
6+
Display the colors from the default prop_cycle, which is obtained from the
7+
:ref:`rc parameters<sphx_glr_tutorials_introductory_customizing.py>`.
78
"""
89
import numpy as np
910
import matplotlib.pyplot as plt
@@ -38,3 +39,21 @@
3839
fig.suptitle('Colors in the default prop_cycle', fontsize='large')
3940

4041
plt.show()
42+
43+
#############################################################################
44+
#
45+
# ------------
46+
#
47+
# References
48+
# """"""""""
49+
#
50+
# The use of the following functions, methods, classes and modules is shown
51+
# in this example:
52+
53+
import matplotlib
54+
matplotlib.axes.Axes.axhline
55+
matplotlib.axes.Axes.axvline
56+
matplotlib.pyplot.axhline
57+
matplotlib.pyplot.axvline
58+
matplotlib.axes.Axes.set_facecolor
59+
matplotlib.figure.Figure.suptitle

examples/color/color_cycler.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
99
This example demonstrates two different APIs:
1010
11-
1. Setting the default rc parameter specifying the property cycle.
12-
This affects all subsequent axes (but not axes already created).
11+
1. Setting the default
12+
:ref:`rc parameter<sphx_glr_tutorials_introductory_customizing.py>`
13+
specifying the property cycle. This affects all subsequent axes
14+
(but not axes already created).
1315
2. Setting the property cycle for a single pair of axes.
1416
"""
1517
from cycler import cycler
@@ -39,3 +41,17 @@
3941
# Tweak spacing between subplots to prevent labels from overlapping
4042
fig.subplots_adjust(hspace=0.3)
4143
plt.show()
44+
45+
#############################################################################
46+
#
47+
# ------------
48+
#
49+
# References
50+
# """"""""""
51+
#
52+
# The use of the following functions, methods, classes and modules is shown
53+
# in this example:
54+
55+
import matplotlib
56+
matplotlib.axes.Axes.plot
57+
matplotlib.axes.Axes.set_prop_cycle

examples/color/color_demo.py

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,75 @@
33
Color Demo
44
==========
55
6-
matplotlib gives you 5 ways to specify colors,
6+
Matplotlib gives you 8 ways to specify colors,
77
8-
1) as a single letter string, ala MATLAB
8+
1) an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g. ``(0.1, 0.2, 0.5)``
9+
or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha;
10+
2) a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0F0F0F0F'``);
11+
3) a string representation of a float value in ``[0, 1]`` inclusive for gray
12+
level (e.g., ``'0.5'``);
13+
4) a single letter string, i.e. one of
14+
``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``;
15+
5) a X11/CSS4 ("html") color name, e.g. ``"blue"``;
16+
6) a name from the `xkcd color survey <https://xkcd.com/color/rgb/>`__,
17+
prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``);
18+
7) a "Cn" color spec, i.e. `'C'` followed by a single digit, which is an index
19+
into the default property cycle
20+
(``matplotlib.rcParams['axes.prop_cycle']``); the indexing occurs at artist
21+
creation time and defaults to black if the cycle does not include color.
22+
8) one of ``{'tab:blue', 'tab:orange', 'tab:green',
23+
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
24+
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
25+
'tab10' categorical palette (which is the default color cycle);
926
10-
2) as an html style hex string or html color name
27+
For more information on colors in matplotlib see
1128
12-
3) as an R,G,B tuple, where R,G,B, range from 0-1
13-
14-
4) as a string representing a floating point number
15-
from 0 to 1, corresponding to shades of gray.
16-
17-
5) as a special color "Cn", where n is a number 0-9 specifying the
18-
nth color in the currently active color cycle.
19-
20-
See help(colors) for more info.
29+
* the :ref:`sphx_glr_tutorials_colors_colors.py` tutorial;
30+
* the `matplotlib.colors` API;
31+
* the :ref:`sphx_glr_gallery_color_named_colors.py` example.
2132
"""
33+
2234
import matplotlib.pyplot as plt
2335
import numpy as np
2436

25-
t = np.arange(0.0, 2.0, 0.01)
37+
t = np.linspace(0.0, 2.0, 201)
2638
s = np.sin(2 * np.pi * t)
2739

28-
fig, ax = plt.subplots(facecolor='darkslategray')
29-
ax.plot(t, s, 'C1')
30-
ax.set_xlabel('time (s)', color='C1')
31-
ax.set_ylabel('voltage (mV)', color='0.5') # grayscale color
32-
ax.set_title('About as silly as it gets, folks', color='#afeeee')
40+
# 1) RGB tuple:
41+
fig, ax = plt.subplots(facecolor=(.18, .31, .31))
42+
# 2) hex string:
43+
ax.set_facecolor('#eafff5')
44+
# 3) gray level string:
45+
ax.set_title('Voltage vs. time chart', color='0.7')
46+
# 4) single letter color string
47+
ax.set_xlabel('time (s)', color='c')
48+
# 5) a named color:
49+
ax.set_ylabel('voltage (mV)', color='peachpuff')
50+
# 6) a named xkcd color:
51+
ax.plot(t, s, 'xkcd:crimson')
52+
# 7) Cn notation:
53+
ax.plot(t, .7*s, color='C4', linestyle='--')
54+
# 8) tab notation:
55+
ax.tick_params(labelcolor='tab:orange')
56+
3357

3458
plt.show()
59+
60+
#############################################################################
61+
#
62+
# ------------
63+
#
64+
# References
65+
# """"""""""
66+
#
67+
# The use of the following functions, methods, classes and modules is shown
68+
# in this example:
69+
70+
import matplotlib
71+
matplotlib.colors
72+
matplotlib.axes.Axes.plot
73+
matplotlib.axes.Axes.set_facecolor
74+
matplotlib.axes.Axes.set_title
75+
matplotlib.axes.Axes.set_xlabel
76+
matplotlib.axes.Axes.set_ylabel
77+
matplotlib.axes.Axes.tick_params

examples/color/colorbar_basics.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Colorbar
44
========
55
6-
Use colorbar by specifying the mappable object (here
7-
the imshow returned object) and the axes to attach the colorbar to.
6+
Use `~.figure.Figure.colorbar` by specifying the mappable object (here
7+
the `~.matplotlib.image.AxesImage` returned by `~.axes.Axes.imshow`)
8+
and the axes to attach the colorbar to.
89
"""
910

1011
import numpy as np
@@ -35,3 +36,19 @@
3536
fig.colorbar(neg, ax=ax2)
3637

3738
plt.show()
39+
40+
#############################################################################
41+
#
42+
# ------------
43+
#
44+
# References
45+
# """"""""""
46+
#
47+
# The use of the following functions, methods, classes and modules is shown
48+
# in this example:
49+
50+
import matplotlib
51+
matplotlib.axes.Axes.imshow
52+
matplotlib.pyplot.imshow
53+
matplotlib.figure.Figure.colorbar
54+
matplotlib.pyplot.colorbar

examples/color/colormap_reference.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,19 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
6565
plot_color_gradients(cmap_category, cmap_list, nrows)
6666

6767
plt.show()
68+
69+
#############################################################################
70+
#
71+
# ------------
72+
#
73+
# References
74+
# """"""""""
75+
#
76+
# The use of the following functions, methods, classes and modules is shown
77+
# in this example:
78+
79+
import matplotlib
80+
matplotlib.colors
81+
matplotlib.axes.Axes.imshow
82+
matplotlib.figure.Figure.text
83+
matplotlib.axes.Axes.set_axis_off

examples/color/named_colors.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
========================
55
66
Simple plot example with the named colors and its visual representation.
7+
8+
For more information on colors in matplotlib see
9+
10+
* the :ref:`sphx_glr_tutorials_colors_colors.py` tutorial;
11+
* the `matplotlib.colors` API;
12+
* the :ref:`sphx_glr_gallery_color_color_demo.py`.
713
"""
814
from __future__ import division
915

@@ -53,3 +59,22 @@
5359
top=1, bottom=0,
5460
hspace=0, wspace=0)
5561
plt.show()
62+
63+
#############################################################################
64+
#
65+
# ------------
66+
#
67+
# References
68+
# """"""""""
69+
#
70+
# The use of the following functions, methods, classes and modules is shown
71+
# in this example:
72+
73+
import matplotlib
74+
matplotlib.colors
75+
matplotlib.colors.rgb_to_hsv
76+
matplotlib.colors.to_rgba
77+
matplotlib.figure.Figure.get_size_inches
78+
matplotlib.figure.Figure.subplots_adjust
79+
matplotlib.axes.Axes.text
80+
matplotlib.axes.Axes.hlines

examples/images_contours_and_fields/affine_image.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Affine transform of an image
44
============================
55
6+
7+
Prepending an affine transformation (:class:`~.transforms.Affine2D`)
8+
to the :ref:`data transform <data-coords>`
9+
of an image allows to manipulate the image's shape and orientation.
10+
This is an example of the concept of
11+
:ref:`transform chaining <transformation-pipeline>`.
12+
613
For the backends that support draw_image with optional affine
714
transform (e.g., agg, ps backend), the image of the output should
815
have its boundary match the dashed yellow rectangle.
@@ -57,3 +64,19 @@ def do_plot(ax, Z, transform):
5764
rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1))
5865

5966
plt.show()
67+
68+
69+
#############################################################################
70+
#
71+
# ------------
72+
#
73+
# References
74+
# """"""""""
75+
#
76+
# The use of the following functions, methods and classes is shown
77+
# in this example:
78+
79+
import matplotlib
80+
matplotlib.axes.Axes.imshow
81+
matplotlib.pyplot.imshow
82+
matplotlib.transforms.Affine2D

examples/images_contours_and_fields/barb_demo.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,23 @@
2222
data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
2323
('u', np.float32), ('v', np.float32)])
2424

25+
fig1, axs1 = plt.subplots(nrows=2, ncols=2)
2526
# Default parameters, uniform grid
26-
ax = plt.subplot(2, 2, 1)
27-
ax.barbs(X, Y, U, V)
27+
axs1[0, 0].barbs(X, Y, U, V)
2828

2929
# Arbitrary set of vectors, make them longer and change the pivot point
3030
# (point around which they're rotated) to be the middle
31-
ax = plt.subplot(2, 2, 2)
32-
ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')
31+
axs1[0, 1].barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')
3332

3433
# Showing colormapping with uniform grid. Fill the circle for an empty barb,
3534
# don't round the values, and change some of the size parameters
36-
ax = plt.subplot(2, 2, 3)
37-
ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
38-
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
35+
axs1[1, 0].barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
36+
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
3937

4038
# Change colors as well as the increments for parts of the barbs
41-
ax = plt.subplot(2, 2, 4)
42-
ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
43-
barbcolor=['b', 'g'],
44-
barb_increments=dict(half=10, full=20, flag=100), flip_barb=True)
39+
axs1[1, 1].barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
40+
barbcolor=['b', 'g'], flip_barb=True,
41+
barb_increments=dict(half=10, full=20, flag=100))
4542

4643
# Masked arrays are also supported
4744
masked_u = np.ma.masked_array(data['u'])
@@ -50,8 +47,21 @@
5047

5148
# Identical plot to panel 2 in the first figure, but with the point at
5249
# (0.5, 0.25) missing (masked)
53-
fig2 = plt.figure()
54-
ax = fig2.add_subplot(1, 1, 1)
55-
ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')
50+
fig2, ax2 = plt.subplots()
51+
ax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')
5652

5753
plt.show()
54+
55+
#############################################################################
56+
#
57+
# ------------
58+
#
59+
# References
60+
# """"""""""
61+
#
62+
# The use of the following functions, methods and classes is shown
63+
# in this example:
64+
65+
import matplotlib
66+
matplotlib.axes.Axes.barbs
67+
matplotlib.pyplot.barbs

examples/images_contours_and_fields/barcode_demo.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Barcode Demo
44
============
55
6+
This demo shows how to produce a one-dimensional image, or "bar code".
67
"""
78
import matplotlib.pyplot as plt
89
import numpy as np
@@ -19,13 +20,27 @@
1920

2021
fig = plt.figure()
2122

22-
# a vertical barcode -- this is broken at present
23-
ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
24-
ax.imshow(x.reshape((-1, 1)), **barprops)
23+
# a vertical barcode
24+
ax1 = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
25+
ax1.imshow(x.reshape((-1, 1)), **barprops)
2526

2627
# a horizontal barcode
27-
ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
28-
ax.imshow(x.reshape((1, -1)), **barprops)
28+
ax2 = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
29+
ax2.imshow(x.reshape((1, -1)), **barprops)
2930

3031

3132
plt.show()
33+
34+
#############################################################################
35+
#
36+
# ------------
37+
#
38+
# References
39+
# """"""""""
40+
#
41+
# The use of the following functions, methods and classes is shown
42+
# in this example:
43+
44+
import matplotlib
45+
matplotlib.axes.Axes.imshow
46+
matplotlib.pyplot.imshow

0 commit comments

Comments
 (0)