Python - 为3d线图着色

时间:2015-03-31 21:21:21

标签: python matplotlib mplot3d

我有一个太阳光谱的三维线图,我使用命令

绘制
from mpl_toolkits.mplot3d.axes3d import Axes3D
from matplotlib.collections import PolyCollection, LineCollection
from matplotlib.colors import colorConverter, ListedColormap, BoundaryNorm
import matplotlib.cm as cm

fig = plt.figure(figsize(15, 8))
ax = fig.gca(projection='3d')

x = SpectrumDF['Wavelength']
z = SpectrumDF['DNI']
y = SpectrumDF['TESTNUM']

ax.plot(x, y, z)
ax.set_xlabel('Wavelength')
ax.set_ylabel('Test Number')
ax.set_zlabel('Intensity')

结果图是纯蓝色,并且取我在函数中给出的任何一种颜色:plot()。

我一直在尝试沿z轴创建颜色渐变,强度,但没有任何成功。

我有大约500个测试号,每个测试号有744个数据点。

感谢您的帮助!

这不会让我发布图片,因为我没有足够的声誉。无论如何,这里是我使用此代码https://plus.google.com/106871046257785761571/posts/fMYsDF5wAQa

获得的情节的链接

enter image description here

1 个答案:

答案 0 :(得分:1)

使用示例 - Line colour of 3D parametric curve in python's matplotlib.pyplot - 我得到了一个沿z轴颜色渐变的散点图 - 这里是指向该图的图像的链接 - https://plus.google.com/u/0/106871046257785761571/posts/SHTsntgQxTw?pid=6133159284332945618&oid=106871046257785761571

enter image description here

我使用了以下命令:

fig = plt.figure(figsize(15,8))
ax = fig.gca(projection='3d')

x = FilteredDF['Wavelength']
z = FilteredDF['DNI']
y = FilteredDF['TESTNUM']

ax.scatter(x, y, z, c=plt.cm.jet(z/max(z)))

ax.set_xlabel('Wavelength')
ax.set_ylabel('Test Number')
ax.set_zlabel('Intensity')

plt.show()

我仍在努力获得彩色线条图,因为我有很多点,这使得散点图很难处理。

谢谢

相关问题