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