如何连接 3D 散点图上的点? [英] How can I connect points on a 3D scatter plot?

查看:24
本文介绍了如何连接 3D 散点图上的点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以目前,我拥有所有这些坐标,因此很容易创建所有坐标组合的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆