[英]Two different graphs in the same plot
I want to plot a wirerframe and a scatter plot in the same plot. 我想在同一个图中绘制一个wirerframe和一个散点图。 Here's what I do:
这是我做的:
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()
This script just gives the scatter plot. 此脚本仅提供散点图。 Comment any block and you get the uncommented plot.
评论任何块,你会得到未注释的情节。 But they won't go on the same plot together.
但他们不会一起出现在同一个阴谋中。
When you add_subplot(111)
again, you override the previous subplot. 再次添加
add_subplot(111)
时,将覆盖上一个子图。 Just don't do that, and plot on the same axes twice: 只是不要这样做,并在同一轴上绘制两次:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.