Note
Go to the endto download the full example code.
List of named colors#
This plots a list of the named colors supported by Matplotlib.For more information on colors in matplotlib see
theSpecifying colors tutorial;
the
matplotlib.colorsAPI;theColor Demo.
Helper Function for Plotting#
First we define a helper function for making a table of colors, then we use iton some common color categories.
importmathimportmatplotlib.pyplotaspltimportmatplotlib.colorsasmcolorsfrommatplotlib.patchesimportRectangledefplot_colortable(colors,*,ncols=4,sort_colors=True):cell_width=212cell_height=22swatch_width=48margin=12# Sort colors by hue, saturation, value and name.ifsort_colorsisTrue:names=sorted(colors,key=lambdac:tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(c))))else:names=list(colors)n=len(names)nrows=math.ceil(n/ncols)width=cell_width*ncols+2*marginheight=cell_height*nrows+2*margindpi=72fig,ax=plt.subplots(figsize=(width/dpi,height/dpi),dpi=dpi)fig.subplots_adjust(margin/width,margin/height,(width-margin)/width,(height-margin)/height)ax.set_xlim(0,cell_width*ncols)ax.set_ylim(cell_height*(nrows-0.5),-cell_height/2.)ax.yaxis.set_visible(False)ax.xaxis.set_visible(False)ax.set_axis_off()fori,nameinenumerate(names):row=i%nrowscol=i//nrowsy=row*cell_heightswatch_start_x=cell_width*coltext_pos_x=cell_width*col+swatch_width+7ax.text(text_pos_x,y,name,fontsize=14,horizontalalignment='left',verticalalignment='center')ax.add_patch(Rectangle(xy=(swatch_start_x,y-9),width=swatch_width,height=18,facecolor=colors[name],edgecolor='0.7'))returnfig
Base colors#
plot_colortable(mcolors.BASE_COLORS,ncols=3,sort_colors=False)

Tableau Palette#
plot_colortable(mcolors.TABLEAU_COLORS,ncols=2,sort_colors=False)

CSS Colors#
plot_colortable(mcolors.CSS4_COLORS)plt.show()

XKCD Colors#
Matplotlib supports colors from thexkcd color survey, e.g."xkcd:skyblue". Sincethis contains almost 1000 colors, a figure of this would be very large and is thusomitted here. You can use the following code to generate the overview yourself
xkcd_fig=plot_colortable(mcolors.XKCD_COLORS)xkcd_fig.savefig("XKCD_Colors.png")
References
The use of the following functions, methods, classes and modules is shownin this example:
Tags:styling: colorpurpose: reference
Total running time of the script: (0 minutes 1.774 seconds)