- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine Matplotlib axis size in pixels
To determine the axis size in pixels, we can take the following steps −
Create a figure and a set of subplots, using subplots() method, fig and ax.
To get the DPI, use fig.dpi. Print the details.
Find bounding box in the display box.
Find the width and height, using bbox.width and bbox.height.
Print the width and height.
Example
from matplotlib import pyplot as plt fig, ax = plt.subplots() print("Dot per inch(DPI) for the figure is: ", fig.dpi) bbox = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) width, height = bbox.width, bbox.height print("Axis sizes are(in pixels):", width, height)
Output
Dot per inch(DPI) for the figure is: 100.0 Axis sizes are(in pixels): 4.96 3.696
- Related Articles
- Setting Font Size with Pixels in CSS
- How to set the font size of Matplotlib axis Legend?
- Set Font Size with Pixels using CSS
- Setting Font Size with Pixels using CSS
- C++ code to find screen size with n pixels
- Hide axis values but keep axis tick labels in matplotlib
- Set variable point size in Matplotlib
- How to enforce axis range in Matplotlib?
- Setting Y-axis in Matplotlib using Pandas
- How to pixelate a square image to 256 big pixels with Python Matplotlib?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- Adding extra axis ticks using Matplotlib
- Changing the color of an axis in Matplotlib
- How to customize the X-axis in Matplotlib?
- How to customize X-axis ticks in Matplotlib?

Advertisements