My Authors
Read all threads
Explanation of matplotlib "inches" - a tutorial thread

Inches is a relative term. You must know the figure dpi (dots per inch) and your screen's dpi to make sense of it. Default inline dpi is 72. Below figure is 5 x 2 "figure inches" or 360 x 144 pixels.
Using a screen ruler program (Onde Rulers) it actually measures as 2.2 x .98 "screen inches" on my screen and 324 x 144 pixels
Why not 360 x 144 pixels? Because figures are displayed in the notebook with setting bbox_inches set to 'tight' which trims some of the figure.
Set this to None and figure will be exactly 360 x 144 pixels. Notice a little more extra width on both sides.
To make matplotlib figure inches match your screen's inches, find out your screen's dpi. My mac is 2880 by 1800 but renders as 1920 x 1200. Using pythogren thm, it's diagonal is 2,264 pixels. My screen diagonal is 15.4 inches. Divide these numbers to get a DPI of 147.
Creating a new figure with the same 5 x 2 figure inches with 147 DPI gets an image that is exactly 5 x 2 screen inches on my screen.
If the screen inches are wider than the output display of the notebook, then it will get scaled down, so even if you use your screen's DPI, it won't visually appear in the notebook with those screen inches.
Extra: Matplotlib documentation states that default figure size is 6.4 x 4.8 and dpi is 100, but in the notebook you'll get 6 x 4 and 72. This is because notebooks override a few settings that you can find with the %config command.
I am releasing about 150 pages with exercises on matplotlib this week that is part of my book Master Data Analysis with Python. It covers all these details and much more.

dunderdata.com/master-data-an…
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Ted Petrou

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!