Figure Style and Scale: Darkgrid Whitegrid Dark White Ticks Darkgrid
Figure Style and Scale: Darkgrid Whitegrid Dark White Ticks Darkgrid
Figure Style and Scale: Darkgrid Whitegrid Dark White Ticks Darkgrid
Introduction
When creating a data visualization, your goal is to communicate the insights found in the
data. While visualizing communicates important information, styling will influence how
your audience understands what you’re trying to convey.
After you have formatted and visualized your data, the third and last step of data
visualization is styling. Styling is the process of customizing the overall look of your
visualization, or figure. Making intentional decisions about the details of the visualization
will increase their impact and set your work apart.
● customize the overall look of your figure, using background colors, grids, spines,
and ticks
● scale plots for different contexts, such as presentations and reports
In this section, we’ll explore three main aspects of customizing figures in Seaborn -
background color, grids, and spines - and how these elements can change the look and
meaning of your visualizations.
Built-in Themes
Seaborn has five built-in themes to style its plots: darkgrid, whitegrid, dark, white, and
ticks. Seaborn defaults to using the darkgrid theme for its plots, but you can change
this styling to better suit your presentation needs.
sns.set_style("darkgrid")
Background Color
When thinking about the look of your visualization, one thing to consider is the background
color of your plot. The higher the contrast between the color palette of your plot and your
figure background, the more legible your data visualization will be. Fun fact: dark blue on
white is actually more legible than black on white!
The dark background themes provide a nice change from the Matplotlib styling norms, but
doesn’t have as much contrast:
sns.set_style("dark")
The white and tick themes will allow the colors of your dataset to show more visibly and
provides higher contrast so your plots are more legible:
sns.set_style("ticks")
It’s a good choice to use a grid when you want your audience to be able to draw their own
conclusions about data. A grid allows the audience to read your chart and get specific
information about certain values. Research papers and reports are a good example of
when you would want to include a grid.
sns.set_style("whitegrid")
There are also instances where it would make more sense to not use a grid. If you’re
delivering a presentation, simplifying your charts in order to draw attention to the
important visual details may mean taking out the grid. If you’re interested in making more
specific design choices, then leaving out the grids might be part of that aesthetic decision.
sns.set_style("white")
Despine
In addition to changing the color background, you can also define the usage of spines.
Spines are the borders of the figure that contain the visualization. By default, an image has
four spines.
You may want to remove some or all of the spines for various reasons. A figure with the
left and bottom spines resembles traditional graphs. You can automatically take away the
top and right spines using the sns.despine()function. Note: this function must be called
after you have called your plot.
sns.set_style("white")
sns.stripplot(x="day", y="total_bill", data=tips)
sns.despine()
Not including any spines at all may be an aesthetic decision. You can also specify how
many spines you want to include by calling despine() and passing in the spines you want
to get rid of, such as: left, bottom, top, right.
sns.set_style("whitegrid")
sns.despine(left=True, bottom=True)
Scaling Plots
Seaborn has four presets which set the size of the plot and allow you to customize your
figure depending on how it will be presented.
In order of relative size they are: paper, notebook, talk, and poster. The notebook style
is the default.
sns.set_style("ticks")
# Smallest context:
sns.set_context("paper")
sns.stripplot(x="day", y="total_bill", data=tips)
sns.set_style("ticks")
# Largest Context:
sns.set_context("poster")
sns.stripplot(x="day", y="total_bill", data=tips)
You may want to also change the line width so it matches. We do this with the rc
parameter, which we’ll explain in detail below.
The RC Parameter
As we mentioned above, if you want to override any of these standards, you can use
sns.set_context and pass in the parameter rc to target and reset the value of an
individual parameter in a dictionary. rc stands for the phrase ‘run command’ - essentially,
configurations which will execute when you run your code.
sns.set_style("ticks")
sns.set_context("poster")
sns.stripplot(x="day", y="total_bill", data=tips)
sns.plotting_context()
Returns:
{'axes.labelsize': 17.6,
'axes.titlesize': 19.200000000000003,
'font.size': 19.200000000000003,
'grid.linewidth': 1.6,
'legend.fontsize': 16.0,
'lines.linewidth': 2.8000000000000003,
'lines.markeredgewidth': 0.0,
'lines.markersize': 11.200000000000001,
'patch.linewidth': 0.48,
'xtick.labelsize': 16.0,
'xtick.major.pad': 11.200000000000001,
'xtick.major.width': 1.6,
'xtick.minor.width': 0.8,
'ytick.labelsize': 16.0,
'ytick.major.pad': 11.200000000000001,
'ytick.major.width': 1.6,
'ytick.minor.width': 0.8}
Conclusion
As you can see, Seaborn offers a lot of opportunities to customize your plots and have
them show a distinct style. The color of your background, background style such as lines
and ticks, and the size of your font all play a role in improving legibility and aesthetics.
Color
Introduction
When creating a data visualization, your goal is to communicate the insights found in the
data. While visualizing communicates important information, styling will influence how
your audience understands what you’re trying to convey.
After you have formatted and visualized your data, the third and last step of data
visualization is styling. Styling is the process of customizing the overall look of your
visualization, or figure. Making intentional decisions about the details of the visualization
will increase their impact and set your work apart.
In this article, we’ll look at how we can effectively use color to convey meaning. We’ll
cover:
If you want to quickly see what a palette looks like, use the function sns.palplot() to
plot a palette as an array of colors:
To select and set a palette in Seaborn, use the command sns.set_palette() and pass in
the name of the palette that you would like to use:
Seaborn has six variations of its default color palette: deep, muted, pastel, bright, dark,
and colorblind.
To use, pass the name of any Color Brewer palette directly to any of the color functions:
custom_palette = sns.color_palette("Paired", 9)
sns.palplot(custom_palette)
Here is a list of the the Color Brewer palettes, with their names for easy reference:
Check out http://colorbrewer2.org for more information about color palette configuration
options.
An example of categorical data is breed of dog. Each of these values, such as Border
Collie or Poodle, are distinct from each other but there isn’t any inherent order to these
categories.
Sequential Palettes
Just as the name implies, sequential palettes are a set of colors that move sequentially
from a lighter to a darker color. Sequential color palettes are appropriate when a variable
exists as ordered categories, such as grade in school, or as continuous values that can be
put into groups, such as yearly income. Because the darkest colors will attract the most
visual attention, sequential palettes are most useful when only high values need to be
emphasized.
Diverging Palettes
Diverging palettes are best suited for datasets where both the low and high values might
be of equal interest, such as hot and cold temperatures.
In the example below, both ends of the spectrum — fire red and deep blue — are likely to
attract attention.
Summary
The ability to use easily choose different color palettes is one of the important affordances
of styling your plots with Seaborn. Seaborn gives you a range of built-in plots to choose
from: whether it’s variations on the defaults or access to all of the Color Brewer palettes.
It’s easy to choose a palette that is well suited to your dataset, thanks to Color Brewer, as it
supports palettes for qualitative, sequential, and diverging datasets.