确定像素的 matplotlib 轴大小
要确定像素的轴大小,我们可以采取以下步骤 −
创建一个图形和一组子图,使用 subplots() 方法,fig 和 ax。
要获取 DPI,使用 fig.dpi。打印详细信息。
在显示框中查找边框框。
使用 bbox.width 和 bbox.height 查找宽度和高度。
打印宽度和高度。
示例
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)输出
Dot per inch(DPI) for the figure is: 100.0 Axis sizes are(in pixels): 4.96 3.696
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP