我刚刚安装了最新版本的 Matplotlib (3.4.1)。当我在以下行中使用一些代码时
ax = fig.gca(projection='3d')
Run Code Online (Sandbox Code Playgroud)
我收到以下警告:
Run Code Online (Sandbox Code Playgroud)Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
我如何解决这个问题,以便我的代码不发出此警告?
小智 9
fig = plt.figure()
plt.subplot(projection='3d')
plt.plot([0, v1[0]], [0, v1[1]], [0, v1[2]], 'b')
plt.plot([0, v2[0]], [0, v2[1]], [0, v2[2]], 'r')
Run Code Online (Sandbox Code Playgroud)
或者
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.plot([0, v1[0]], [0, v1[1]], [0, v1[2]], 'b')
ax.plot([0, v2[0]], [0, v2[1]], [0, v2[2]], 'r')
Run Code Online (Sandbox Code Playgroud)
代替
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot([0, v1[0]], [0, v1[1]], [0, v1[2]], 'b')
ax.plot([0, v2[0]], [0, v2[1]], [0, v2[2]], 'r')
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮到你,
小智 5
你可以试试:
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
Run Code Online (Sandbox Code Playgroud)