【问题标题】:Change figsize in matplotlib polar contourf更改 matplotlib 极坐标轮廓中的 figsize
【发布时间】:2013-03-08 17:47:56
【问题描述】:

我正在使用以下示例Example 创建两个极坐标等值线子图。当我创建为 pdf 时,我想通过更改 figsize 来删除很多空白。

我通常知道如何更改 figsize,但我很难看到在此代码示例中将其放在何处。任何指导或提示将不胜感激。

非常感谢!

import numpy as np
import matplotlib.pyplot as plt

#-- Generate Data -----------------------------------------
# Using linspace so that the endpoint of 360 is included...
azimuths = np.radians(np.linspace(0, 360, 20))
zeniths = np.arange(0, 70, 10)

r, theta = np.meshgrid(zeniths, azimuths)
values = np.random.random((azimuths.size, zeniths.size))

#-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)

plt.show()

【问题讨论】:

    标签: matplotlib


    【解决方案1】:

    另一种方法是在您对plt.subplots 的调用中使用figsize kwarg。

    fig, ax = plt.subplots(figsize=(6,6), subplot_kw=dict(projection='polar')).

    顺便说一下,这些值以英寸为单位。

    【讨论】:

      【解决方案2】:

      您可以轻松地将plt.figsize(x,y) 放在代码的开头,它会起作用。 plt.figsize 改变所有未来图的大小,而不仅仅是当前图。

      但是,我认为您的问题不是您想的那样。除非您更改选项,否则生成的 PDF 中往往会有相当多的空白。我通常使用

      plt.savefig( 'name.pdf', bbox_inches='tight', pad_inches=0 )
      

      这会提供尽可能少的空白。 bbox_inches='tight' 试图使边界框尽可能小,而 pad_inches 设置应该填充多少英寸的空白。在我的情况下,我根本没有额外的填充,因为我在使用该图的任何内容中添加了填充。

      【讨论】:

      • 谢谢,我不知道 savefig 中的 cmets - 这很有帮助。实际上在代码开头使用 plt.figsize=(5,5) 对我的输出没有影响。
      • 如果你在做 plt.figsize=(5,5) 那是行不通的;它需要 plt.figsize(5,5) 没有等号。有一个函数 figsize 设置默认图形大小,还有一个命名参数 figsize 到 figure 和 subplots 设置该特定图形的 figsize。
      猜你喜欢
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-02
      • 2022-01-24
      相关资源
      最近更新 更多