Skip to content

Commit fdaa72e

Browse files
example references for shapes&collections
1 parent 8a29c40 commit fdaa72e

28 files changed

+589
-63
lines changed

examples/color/color_by_yvalue.py

+14
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

+20-1
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

+18-2
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
@@ -43,3 +45,17 @@
4345
# Tweak spacing between subplots to prevent labels from overlapping
4446
fig.subplots_adjust(hspace=0.3)
4547
plt.show()
48+
49+
#############################################################################
50+
#
51+
# ------------
52+
#
53+
# References
54+
# """"""""""
55+
#
56+
# The use of the following functions, methods, classes and modules is shown
57+
# in this example:
58+
59+
import matplotlib
60+
matplotlib.axes.Axes.plot
61+
matplotlib.axes.Axes.set_prop_cycle

examples/color/color_demo.py

+61-18
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

+19-2
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

+16
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

+25
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

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

examples/pie_and_polar_charts/nested_pie.py

+19
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,22 @@
7676
ax.set(title="Pie plot with `ax.bar` and polar coordinates")
7777
ax.set_axis_off()
7878
plt.show()
79+
80+
#############################################################################
81+
#
82+
# ------------
83+
#
84+
# References
85+
# """"""""""
86+
#
87+
# The use of the following functions, methods, classes and modules is shown
88+
# in this example:
89+
90+
import matplotlib
91+
matplotlib.axes.Axes.pie
92+
matplotlib.pyplot.pie
93+
matplotlib.axes.Axes.bar
94+
matplotlib.pyplot.bar
95+
matplotlib.projections.polar
96+
matplotlib.axes.Axes.set
97+
matplotlib.axes.Axes.set_axis_off

examples/pie_and_polar_charts/pie_and_donut_labels.py

+17
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,20 @@ def func(pct, allvals):
123123
# And here it is, the donut. Note however, that if we were to use this recipe,
124124
# the ingredients would suffice for around 6 donuts - producing one huge
125125
# donut is untested and might result in kitchen errors.
126+
127+
128+
#############################################################################
129+
#
130+
# ------------
131+
#
132+
# References
133+
# """"""""""
134+
#
135+
# The use of the following functions, methods, classes and modules is shown
136+
# in this example:
137+
138+
import matplotlib
139+
matplotlib.axes.Axes.pie
140+
matplotlib.pyplot.pie
141+
matplotlib.axes.Axes.legend
142+
matplotlib.pyplot.legend

examples/pie_and_polar_charts/pie_demo2.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Pie Demo2
44
=========
55
6-
Make a pie charts using :meth:`.Axes.pie`.
6+
Make a pie charts using :meth:`~.axes.Axes.pie`.
77
88
This example demonstrates some pie chart features like labels, varying size,
99
autolabeling the percentage, offsetting a slice and adding a shadow.
@@ -44,3 +44,17 @@
4444
autotexts[0].set_color('white')
4545

4646
plt.show()
47+
48+
#############################################################################
49+
#
50+
# ------------
51+
#
52+
# References
53+
# """"""""""
54+
#
55+
# The use of the following functions, methods, classes and modules is shown
56+
# in this example:
57+
58+
import matplotlib
59+
matplotlib.axes.Axes.pie
60+
matplotlib.pyplot.pie

examples/pie_and_polar_charts/pie_features.py

+14
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,17 @@
3333
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
3434

3535
plt.show()
36+
37+
#############################################################################
38+
#
39+
# ------------
40+
#
41+
# References
42+
# """"""""""
43+
#
44+
# The use of the following functions, methods, classes and modules is shown
45+
# in this example:
46+
47+
import matplotlib
48+
matplotlib.axes.Axes.pie
49+
matplotlib.pyplot.pie

examples/pie_and_polar_charts/polar_bar.py

+15
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@
2727
bar.set_alpha(0.5)
2828

2929
plt.show()
30+
31+
#############################################################################
32+
#
33+
# ------------
34+
#
35+
# References
36+
# """"""""""
37+
#
38+
# The use of the following functions, methods, classes and modules is shown
39+
# in this example:
40+
41+
import matplotlib
42+
matplotlib.axes.Axes.bar
43+
matplotlib.pyplot.bar
44+
matplotlib.projections.polar

examples/pie_and_polar_charts/polar_demo.py

+18
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,21 @@
2121

2222
ax.set_title("A line plot on a polar axis", va='bottom')
2323
plt.show()
24+
25+
#############################################################################
26+
#
27+
# ------------
28+
#
29+
# References
30+
# """"""""""
31+
#
32+
# The use of the following functions, methods, classes and modules is shown
33+
# in this example:
34+
35+
import matplotlib
36+
matplotlib.axes.Axes.plot
37+
matplotlib.projections.polar
38+
matplotlib.projections.polar.PolarAxes
39+
matplotlib.projections.polar.PolarAxes.set_rticks
40+
matplotlib.projections.polar.PolarAxes.set_rmax
41+
matplotlib.projections.polar.PolarAxes.set_rlabel_position

0 commit comments

Comments
 (0)