大多数面向对象matplotlib的示例都得到一个Axis对象,其内容如下
import matplotlib.pyplot as plt
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(...... etc.我一直认为这是不明显的,特别是从matlab的角度。我最近发现,可以通过
ax1 = fig1.gca() # "GetCurrentAxis"这对我来说更有意义(可能只是因为之前使用Matlab )。为什么add_subplot()选择了一个令人困惑的111个参数作为获取轴对象的首选方法?功能上有什么不同吗?
谢谢!
发布于 2014-12-01 03:18:10
plt.gca获取当前轴,需要时创建一个轴。在最简单的1轴情况下,它是等价的。
首选的方法是使用plt.subplots (而且文档/示例确实有点滞后,如果您想要开始贡献,更新文档是一个很好的起点):
fig, ax = plt.subplots(1, 1)或
fig, (ax1, ax2) = plt.subplots(2, 1)诸若此类。
发布于 2019-07-17 14:00:18
要创建3D实例,有三种方法:
plt.gca(projection='3d')
plt.subplot(projection='3d')
fig = plt.figure()
fig.add_subplot(111, projection='3d') 也许第三条路更复杂。
https://stackoverflow.com/questions/27221009
复制相似问题