简体   繁体   中英

Python - color a 3d line plot

I have a 3d line plot of the solar spectrum, which I plotted using the command,

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')

The resultant plot is solid blue and takes whichever individual color I give in the function: plot( ).

I have been trying to create a color gradient along the z-axis, intensity, without any success.

I have around 500 test numbers, each has 744 data points.

Thank you for the help!

This wouldn't let me post images because I don't have enough reputation. Anyway, here's the link to the plot I get using this code https://plus.google.com/106871046257785761571/posts/fMYsDF5wAQa

在此处输入图片说明

Using the example - Line colour of 3D parametric curve in python's matplotlib.pyplot - I got a scatter plot with color gradient along the z axis - here's the link to the image of that plot - https://plus.google.com/u/0/106871046257785761571/posts/SHTsntgQxTw?pid=6133159284332945618&oid=106871046257785761571

在此处输入图片说明

I used the following command:

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()

I am still working on getting a colored line plot because I have a lot of points, which makes scatter plot very slow to work with.

Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM