How to get matplotlib figure size

会有一股神秘感。 提交于 2019-11-30 12:29:26

问题


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 ? Thanks, Tristan


回答1:


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


来源:https://stackoverflow.com/questions/29702424/how-to-get-matplotlib-figure-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!