如何更改 matplotlib 对现有轴的子图投影?

matplotlibserver side programmingprogramming更新于 2025/5/5 18:07:17

更改现有轴的投影似乎很难,但我们可以采取以下步骤来创建不同类型的投影 −

  • 使用 subplot() 方法,向当前图形添加一个子图,其中 nrows=1、ncols=3 和当前 index=1

  • 为当前轴添加标题。

  • 使用 subplot() 方法,向当前图形添加一个子图,其中 nrows=1、ncols=3 和 current index=2、projection=hammer

  • 为当前轴添加标题,hammer

  • 使用 subplot()方法,向当前图形添加一个子图,其中nrows=1,ncols=3  current index=3,projection=polar

  • 向当前轴添加标题,polar

  • 要显示图形,请使用 show()方法。

示例

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.subplot(131)
plt.title("1D")
plt.subplot(132, projection="hammer")
plt.title("hammer")
plt.subplot(133, projection="polar")
plt.title("polar")
plt.show()

输出


相关文章