如何获得Matplotlib图形大小 [英] How to get matplotlib figure size
本文介绍了如何获得Matplotlib图形大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于一个项目,我需要知道matplotlib图形的当前大小(以像素为单位),但是我找不到执行该操作的方法. 有人知道该怎么做吗?
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 ?
推荐答案
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
这篇关于如何获得Matplotlib图形大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文