 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
Advertisements
 