A20: Seaborn (Part-5): Statistical Data Visualization (Controlling Figure Aesthetics)
This article is a part of “Data Science from Scratch — Can I to I Can”, A Lecture Notes Book Series. (click here to get your copy today!)
✅ A Suggestion: Open a new jupyter notebook and type the code while reading this article, doing is learning, and yes, “PLEASE Read the comment, they are very useful…..!”
Its time to talk about one of the most important aspect in the data presentation, report writing and storytelling, which is figure aesthetics. This very important aspect if widely ignored by the early stage data scientist which could significantly reduce the impact of all your efforts at the end. Always pay attention to figure aesthetics!
Although, in the previous lectures, we have seen (at least couple of times) how to control figure aesthetics in seaborn, but let’s now go over it formally.
Seaborn figure styles
set_style()
We can set particular styles using set_style()
. <shift+tab>
for doc string
You can try different seaborn's themes: darkgrid, whitegrid, dark, white, and/or ticks
. They are each suited to different applications and personal preferences.
Removing axes spines
despine()
We can remove spine using despine()
method.
By default:top=True, right=True, left=False, bottom=False
Figure size and Aspect
We can simply use matplotlib’s plt.figure(figsize=(width,height)
to change the size of most of the seaborn's plots.
We can control the size and aspect ratio of most seaborn grid plots by passing in parameters: size
, and aspect
. For example:
☞ Good to know: In the 2nd line of the code below, when seaborn
calls matplotlib
, it actually set the figure size to the given size for seaborn
. So, we can actually use our matplotlib
knowledge in combination with seaborn
to set the figure size
and aspect
ratio.
Scaling plot elements
set_context()
The set_context()
allows us to override default parameters:
Parameter context : dict, None, or one of {paper, notebook, talk, poster}
, the style of your presentation!
☞ For more on controlling figure aesthetics, check seaborn’s official documentation chick here.
☞ For more palette options, explore matplotlib color maps
💐Click here to FOLLOW ME for new contents💐
Keep practicing to brush-up and add new skills.
Excellent work!
Your clap and share can help us to reach to someone who is struggling to learn these concepts.
Good luck!
See you in the next lecture on “A19: …………………….!!!”.
Note: This complete course, including video lectures and jupyter notebooks, is available on the following links:
Dr. Junaid Qazi is a Subject Matter Specialist, Data Science & Machine Learning Consultant and a Team Builder. He is a Professional Development Coach, Mentor, Author, and Invited Speaker. He can be reached for consulting projects and/or professional development training via LinkedIn.