在 matplotlib 中对子图使用轴方法时的高分辨率图

High resolution figure when using the axes method for subplots in matplotlib

使用plt.figure创建图形时,可以通过以下方式设置其大小和分辨率:

plt.figure(num=1, figsize=(6, 4), dpi=150)

使用以下代码创建图形时如何获取?

fig, ax = plt.subplots()

我试过下面的代码,但我得到了错误 TypeError: 'Figure' 对象不可调用

ax.figure(num=1, figsize=(6, 4), dpi=150)

感谢您的帮助和建议!

plt.subplots()支持plt.figure()的所有关键字参数,所以要改变分辨率,只需要:

fig, ax = plt.subplots(dpi=150)

看看文档:

编辑:您的代码无法正常工作的原因是 ax.figure 是 Figure 对象,而不是函数。这就是为什么 "not callable."