Figure Scaling and Styling
Learn how to make better visualizations with figure scaling and styling.
We'll cover the following...
Scaling plot elements
Seaborn is a rich visualization library that allows various plot customization options. One such option is a set of parameters that allows us to scale the plot elements. Using this option, we can use the same code to create plots suitable for applications requiring smaller or larger plots.
The seaborn library provides four plot contexts in different sizes. The four preset contexts are as follows:
- Paper
- Notebook
- Talk
- Poster
By default, seaborn uses the notebook style for its plot, as shown in the plot below:
import seaborn as snsimport pandas as pdimport matplotlib.pyplot as plttips_df = sns.load_dataset('tips')sns.pairplot(hue = 'sex' , data = tips_df)plt.savefig('output/graph.png')
We can change the preset value by specifying it in the sns.set_context()
function. Let’s change it to paper style. We can observe from the plot below that the fonts and figure elements in the paper style are relatively smaller than in the notebook style:
import seaborn as snsimport pandas as pdimport matplotlib.pyplot as pltsns.set_context('paper')tips_df = sns.load_dataset('tips')sns.pairplot(hue = 'sex' , data = tips_df)plt.savefig('output/graph.png')
Similarly, as shown in the code below, we set the talk context in the sns.set_context()
function. The font size ...