2014-06-17 83 views
1

我想在同一图中绘制一个线框和一个散点图。以下是我所做的:同一图中的两个不同图

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

fig = plt.figure() 

ax1 = fig.add_subplot(111, projection='3d') 
X, Y, Z = axes3d.get_test_data(0.05) 
ax1.plot_wireframe(X, Y, Z, rstride=10, cstride=10) 

ax2 = fig.add_subplot(111, projection='3d') 
xs = np.array([ 1, 0 ,2 ]) 
ys = np.array([ 1, 0, 2 ]) 
zs = np.array([ 1, 2, 3 ]) 
ax2.scatter(xs, ys, zs) 

plt.show() 

此脚本仅给出散点图。评论任何块,你会得到未注释的情节。但他们不会一起出现在同一个地方。

回答

3

当您再次使用add_subplot(111)时,您将覆盖以前的子图。只是不要这样做,并在相同的坐标轴上绘制两次:

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

fig = plt.figure() 

ax = fig.add_subplot(111, projection='3d') 
X, Y, Z = axes3d.get_test_data(0.05) 
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) 

xs = np.array([ 1, 0 ,2 ]) 
ys = np.array([ 1, 0, 2 ]) 
zs = np.array([ 1, 2, 3 ]) 
ax.scatter(xs, ys, zs) 

plt.show() 
相关问题