【问题标题】:adding 3D subplot to the set of 2D将 3D 子图添加到 2D 集合中
【发布时间】:2017-06-20 23:04:58
【问题描述】:

我想将 matplotlib 1.5.1 中的 3D 图添加到现有的一组 2D 图(子图)中。 2D 绘图在没有 3D 的情况下工作正常,但是当我添加 3D 时,我收到一个错误,即“模块”对象没有属性“plot_surface”。我想保持代码简单,所以我将所有命令应用于 plt 而不创建新图形(还有一种使用 set_xlabel 添加标签的方法),这会使事情变得模棱两可。前 3 个图是简单的 2D 图,最后一个是 3D。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d

y1 = u.nodes.concentration
x1 = u.nodes.x 

plt.figure(figsize=(20, 10))
plt.subplot(221)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x1, y1, '-b')

# Inhibitor plt
y2 = z.nodes.concentration
x2 = z.nodes.x

plt.subplot(222)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x2, y2, '-r')

# Modulator plt
y3 = v.nodes.concentration
x3 = v.nodes.x

plt.subplot(223)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x3, y3, '-g')

#3D plot
plt.subplot(224, projection='3d')

# Grab data.
xx = u_fft_x_norm
yy = [i*time_period for i in xrange(1, times)]
zz = u_timespace

XX, YY = np.meshgrid(xx, yy)
ZZ = zz

# Plot a basic wireframe.
plt.plot_surface(XX, YY, ZZ, rstride=20, cstride=20)
plt.xlabel('Space')
plt.ylabel('Time')
plt.zlabel('Value')
plt.title('Profile')

【问题讨论】:

    标签: python matplotlib plot 3d


    【解决方案1】:

    我猜这个错误是不言自明的。 pyplot 没有 plot_surface 命令。也没有迹象表明应该这样做。查看您找到的所有示例,plot_surface 是轴的属性。

    ax = plt.subplot(224, projection='3d')
    ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-31
      • 2020-12-12
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 2019-05-28
      • 2010-12-25
      相关资源
      最近更新 更多