Colors and fonts

ProPlot registers several new color names and font families, and includes tools for defining your own color names and adding your own font families. These features are described below.

Included colors

ProPlot defines new color names from the XKCD color survey, official Crayola crayon colors, and from the “Open color” Github project. This was inspired by seaborn. Use show_colors to generate tables of these colors. Note that the native matplotlib CSS4 named colors are still registered, but we encourage using colors from the tables instead.

To reduce the number of registered color names to a more manageable size, ProPlot filters the available XKCD and Crayola colors so that they have sufficiently distinct coordinates in the perceptually uniform hue-chroma-luminance colorspace. This makes it a bit easier to pick out colors from the table generated with show_colors. Similar names were also cleaned up – for example, 'reddish' and 'reddy' are changed to 'red'.

[1]:
import proplot as plot
figs = plot.show_colors()
/home/docs/checkouts/readthedocs.org/user_builds/proplot/conda/v0.4.1/lib/python3.7/site-packages/proplot/utils.py:103: ProPlotWarning: Rebuilding font manager.
_images/colors_fonts_4_1.svg
_images/colors_fonts_4_2.svg

Colors from colormaps

If you want to draw an individual color from a colormap or a color cycle, use color=(cmap, coord) or color=(cycle, index) with any command that accepts the color keyword. The coord should be between 0 and 1, while the index is the index on the list of cycle colors. This feature is powered by the ColorDict class. This is useful if you spot a nice color in one of the available colormaps and want to use it for some arbitrary plot element.

[2]:
import proplot as plot
import numpy as np
state = np.random.RandomState(51423)
f, axs = plot.subplots(nrows=2, aspect=2, axwidth=3, share=0)

# Drawing from colormap
ax = axs[0]
cmap = 'deep'
m = ax.pcolormesh([[0], [1]], cmap=cmap, N=1000)
idxs = plot.arange(0, 1, 0.2)
state.shuffle(idxs)
for idx in idxs:
    h = ax.plot(
        (np.random.rand(20) - 0.4).cumsum(), lw=5, color=(cmap, idx),
        label=f'idx {idx:.1f}', legend='r', legend_kw={'ncols': 1}
    )
ax.colorbar(m, loc='ul', locator=0.2, label='colormap')
ax.format(title='Drawing from the Solar colormap', grid=True)

# Drawing from color cycle
ax = axs[1]
idxs = np.arange(6)
state.shuffle(idxs)
for idx in idxs:
    h = ax.plot(
        (np.random.rand(20)-0.4).cumsum(), lw=5, color=('qual1', idx),
        label=f'idx {idx:.0f}', legend='r', legend_kw={'ncols': 1}
    )
ax.format(title='Drawing from the ggplot color cycle')
axs.format(
    xlocator='null', abc=True, abcloc='ur', abcstyle='A.',
    suptitle='Getting individual colors from colormaps and cycles'
)
_images/colors_fonts_7_0.svg

Using your own colors

You can register your own colors by adding .txt files to the ~/.proplot/colors directory and calling register_colors. This command is also called on import. Each file should contain lines that look like color: #xxyyzz where color is the registered color name and #xxyyzz is the HEX color value.

Included fonts

ProPlot adds several open source sans-serif fonts and introduces a show_fonts command to display the available sans-serif fonts on your system (see font_manager). Generally speaking, simple, clean sans-serif fonts are more appropriate for figures than serif fonts.

ProPlot also changes the default font to the Helvetica-lookalike TeX Gyre Heros. Matplotlib uses DejaVu Sans by default because DejaVu Sans is open source, can be included in the matplotlib distribution, and includes glyphs for a wider range of mathematical characters (where you see the “¤” dummy symbol in the below table, that character is unavailable). However Helvetica and Arial are much more mature and (in this developer’s humble opinion) aesthetically pleasing. Thus, while ProPlot prioritizes aesthetics, you may need to switch to a font with more math characters like DejaVu Sans or Fira Math.

[3]:
import proplot as plot
f = plot.show_fonts()
findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans.
_images/colors_fonts_12_1.svg

Using your own fonts

You can register your own fonts by adding files to the ~/.proplot/fonts directory and calling register_fonts. This command is also called on import. To change the default font, use the rc object or modify your ~/.proplotrc.See Configuring proplot for details.

Sometimes the font you would like to use is installed, but the font file is not stored under the matplotlib-compatible .ttf, .otf, or .afm formats. For example, several macOS fonts are unavailable because they are stored as .dfont collections. Also, while matplotlib nominally supports .ttc collections, ProPlot manually removes them because figures with .ttc fonts cannot be saved as PDFs. You can get matplotlib to use these fonts by expanding the “collections” into individual .ttf files with the DFontSplitter application, then saving the files in-place or in the ~/.proplot/fonts folder.

To find font files, check the paths listed in OSXFontDirectories, X11FontDirectories, MSUserFontDirectories, and MSFontDirectories under the font_manager module. Note that if the font in question has a “thin” style, implied by file names with the word Thin, a matplotlib bug may cause these styles to override the “normal” style!