如何连接3D散点图上的点? [英] How can I connect points on a 3D scatter plot?
问题描述
因此,目前,我拥有所有这些坐标,因此创建所有坐标组合的3D散点图非常容易。
fig = plt.figure(figsize =(20,10))
ax = plt.axes(projection ='3d')
z = numpy.transpose(z_coords_row)[0 :100]
x = numpy.transpose(x_coords_row)[0:100]
y = numpy.transpose(y_coords_row)[0:100]
plt.xticks(numpy.arange (-1.5,1.5,.25))
plt.yticks(numpy.arange(-1.5,1.5,.5))
ax.scatter(x,y,z,s = 1)
ax.view_init(elev = 10。,azim = 45)
此代码给了我这样的结果:
So currently, I have all these coordinates and so it's quite easy to create a 3D scatter plot of all the combination of coordinates.
fig = plt.figure(figsize=(20,10))
ax = plt.axes(projection='3d')
z = numpy.transpose(z_coords_row)[0:100]
x = numpy.transpose(x_coords_row)[0:100]
y = numpy.transpose(y_coords_row)[0:100]
plt.xticks(numpy.arange(-1.5, 1.5, .25))
plt.yticks(numpy.arange(-1.5, 1.5, .5))
ax.scatter(x, y, z,s=1)
ax.view_init(elev=10., azim=45)
This code gives me a result as so: http://i.stack.imgur.com/KKw1D.png
I've run into lots of problems trying to connect each point with a line to the next point in sequence. How do I go about connecting each point with the next in the array so that it's a smooth line graph?
If you have enough points using only your coordinates I think what you are looking for is plot3D
. If you need it more smooth line it might be worth looking into scipy.interpolate.RegularGridInterpolator
which would help generate more points, which you could then insert into plot3D
.
Example of usage of plot3D
:
import numpy
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(20,10))
ax = plt.axes(projection='3d')
z_coords_row = numpy.sin(numpy.linspace(0,2*numpy.pi,100))+5
x_coords_row = numpy.sin(numpy.linspace(0,2*numpy.pi,100))
y_coords_row = numpy.cos(numpy.linspace(0,2*numpy.pi,100))
z = numpy.transpose(z_coords_row)[0:100]
x = numpy.transpose(x_coords_row)[0:100]
y = numpy.transpose(y_coords_row)[0:100]
plt.xticks(numpy.arange(-1.5, 1.5, .25))
plt.yticks(numpy.arange(-1.5, 1.5, .5))
ax.scatter(x, y, z,s=5)
ax.plot3D(x,y,z)
ax.view_init(elev=10., azim=45)
这篇关于如何连接3D散点图上的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!