Why Matplotlib Figure Inches Don’t Match Your Screen Inches and How to Fix it
If you’ve worked with the matplotlib data visualization library before, then you’ll be familiar with the term figsize, which is measured in figure inches. In a Jupyter Notebook, these default to 6 inches in width by 4 inches in height. But, if you actually measured the physical screen inches on your monitor, you’re likely to get different numbers. This post details why this mismatch exists and how to change the settings of your plot so that the matplotlib figure inches match the physical screen inches exactly.
Create a plot
We begin by reading in the diamonds dataset and create a scatter plot of carat vs price.
import pandas as pd
diamonds = pd.read_csv('../data/diamonds.csv')
diamonds.head(3)
Jupyter Notebooks automatically crop some of the figure so it tightly wraps around the outer elements. To show the entire figure we need to run the following command.
%config InlineBackend.print_figure_kwargs = {'bbox_inches': None}