For a project, I need to know the current size (in pixels) of my matplotlib figure, but I can't find how to do this. Does anyone know how to do this ?
figsize() takes two parameters- width and height (in inches). By default the values for width and height are 6.4 and 4.8 respectively.
The plotting window size can be found by using dev. size function and we can pass in for inches and cm for centimeters. For example, if we create a plot then we can use dev. size("in") to find the plot size in inches and dev.
The native figure size unit in Matplotlib is inches, deriving from print industry standards. However, users may need to specify their figures in other units like centimeters or pixels.
import matplotlib.plt fig = plt.figure() size = fig.get_size_inches()*fig.dpi # size in pixels
To do it for the current figure,
fig = plt.gcf() size = fig.get_size_inches()*fig.dpi # size in pixels
You can get the same info by doing:
bbox = fig.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) width, height = bbox.width*fig.dpi, bbox.height*fig.dpi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With