大多数面向对象的matplotlib示例都会使用类似以下方式获取一个Axis对象:
import matplotlib.pyplot as plt
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(...... etc.
我一直觉得这是不明显的,尤其是从Matlab的角度来看。
最近我发现可以通过等效结果来获得
ax1 = fig1.gca() # "GetCurrentAxis"
对我来说更有意义(可能仅由于先前使用过Matlab)。
为什么选择具有令人困惑的111参数的add_subplot()作为获取轴对象的首选方式?是否有任何功能上的区别?
谢谢!
plt.subplots()
,除了以下几个: "Surface3d"(gca
),"Multiple Subplots"(subplot
),"streamplot"(fig.add_subplots
),"Polar Plots"(suplot
),XKCD(fig.add_axes
)。来源:https://matplotlib.org/3.2.1/tutorials/introductory/sample_plots.html - Demis