Colors and fonts¶
ProPlot also registers new color names and new font families. These are described below.
Included color names¶
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, as shown below. Note that the native matplotlib CSS4 named colors are still registered, but I encourage using colors from the tables instead.
To reduce the number of registered color names to a more manageable size, XKCD and Crayola colors must have sufficiently distinct coordinates in the HCL perceptually uniform colorspace before they are added to ProPlot. This makes it a bit easier to pick out colors from a 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
f = plot.show_colors()
Sampling colormaps and cycles¶
If you want to draw an individual color from a smooth 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 ColorCacheDict
class.
[2]:
import proplot as plot
import numpy as np
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)
np.random.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)
np.random.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')
Included font names¶
DejaVu Sans is the default matplotlib font, but it’s not very aesthetically pleasing. ProPlot adds a bunch of sans-serif fonts so that you have them on every workstation, introduces a show_fonts
command to display them (see below), and makes Helvetica the default, as in MATLAB. Generally speaking, simple, clean sans-serif fonts are more appropriate for figures than serif fonts.
You can register your own fonts by adding .ttf
and .otf
files to the ~/.proplot/fonts
directory and calling register_fonts
(which is also called on import). To change the default font, use the rc
object or modify your ~/.proplotrc
. See Configuring proplot for details.
[3]:
import proplot as plot
plot.rc.reset()
f = plot.show_fonts()