3
3
List of named colors
4
4
====================
5
5
6
- This plots a list of the named colors supported in matplotlib. Note that
7
- :ref:`xkcd colors <xkcd-colors>` are supported as well, but are not listed here
8
- for brevity.
9
-
6
+ This plots a list of the named colors supported in matplotlib.
10
7
For more information on colors in matplotlib see
11
8
12
9
* the :doc:`/tutorials/colors/colors` tutorial;
13
10
* the `matplotlib.colors` API;
14
11
* the :doc:`/gallery/color/color_demo`.
12
+
13
+ ----------------------------
14
+ Helper Function for Plotting
15
+ ----------------------------
16
+ First we define a helper function for making a table of colors, then we use it
17
+ on some common color categories.
15
18
"""
16
19
17
20
from matplotlib .patches import Rectangle
18
21
import matplotlib .pyplot as plt
19
22
import matplotlib .colors as mcolors
20
23
21
24
22
- def plot_colortable (colors , title , sort_colors = True , emptycols = 0 ):
25
+ def plot_colortable (colors , sort_colors = True , emptycols = 0 ):
23
26
24
27
cell_width = 212
25
28
cell_height = 22
26
29
swatch_width = 48
27
30
margin = 12
28
- topmargin = 40
29
31
30
32
# Sort colors by hue, saturation, value and name.
31
33
if sort_colors is True :
@@ -41,18 +43,17 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
41
43
nrows = n // ncols + int (n % ncols > 0 )
42
44
43
45
width = cell_width * 4 + 2 * margin
44
- height = cell_height * nrows + margin + topmargin
46
+ height = cell_height * nrows + 2 * margin
45
47
dpi = 72
46
48
47
49
fig , ax = plt .subplots (figsize = (width / dpi , height / dpi ), dpi = dpi )
48
50
fig .subplots_adjust (margin / width , margin / height ,
49
- (width - margin )/ width , (height - topmargin )/ height )
51
+ (width - margin )/ width , (height - margin )/ height )
50
52
ax .set_xlim (0 , cell_width * 4 )
51
53
ax .set_ylim (cell_height * (nrows - 0.5 ), - cell_height / 2. )
52
54
ax .yaxis .set_visible (False )
53
55
ax .xaxis .set_visible (False )
54
56
ax .set_axis_off ()
55
- ax .set_title (title , fontsize = 24 , loc = "left" , pad = 10 )
56
57
57
58
for i , name in enumerate (names ):
58
59
row = i % nrows
@@ -73,22 +74,38 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
73
74
74
75
return fig
75
76
76
- plot_colortable ( mcolors . BASE_COLORS , "Base Colors" ,
77
- sort_colors = False , emptycols = 1 )
78
- plot_colortable ( mcolors . TABLEAU_COLORS , "Tableau Palette" ,
79
- sort_colors = False , emptycols = 2 )
77
+ #############################################################################
78
+ # -----------
79
+ # Base colors
80
+ # -----------
80
81
81
- # sphinx_gallery_thumbnail_number = 3
82
- plot_colortable (mcolors .CSS4_COLORS , "CSS Colors" )
82
+ plot_colortable (mcolors .BASE_COLORS , sort_colors = False , emptycols = 1 )
83
83
84
- # Optionally plot the XKCD colors (Caution: will produce large figure)
85
- # xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors")
86
- # xkcd_fig.savefig("XKCD_Colors.png")
84
+ #############################################################################
85
+ # ---------------
86
+ # Tableau Palette
87
+ # ---------------
87
88
88
- plt . show ( )
89
+ plot_colortable ( mcolors . TABLEAU_COLORS , sort_colors = False , emptycols = 2 )
89
90
91
+ #############################################################################
92
+ # ----------
93
+ # CSS Colors
94
+ # ----------
95
+
96
+ # sphinx_gallery_thumbnail_number = 3
97
+ plot_colortable (mcolors .CSS4_COLORS )
98
+ plt .show ()
90
99
91
100
#############################################################################
101
+ # -----------
102
+ # XKCD Colors
103
+ # -----------
104
+ # XKCD colors are supported, but they produce a large figure, so we skip them
105
+ # for now. You can use the following code if desired::
106
+ #
107
+ # xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors")
108
+ # xkcd_fig.savefig("XKCD_Colors.png")
92
109
#
93
110
# .. admonition:: References
94
111
#
0 commit comments