2

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

enter image description here

tom10
  • 67,082
  • 10
  • 127
  • 137
Pooja Kapadia
  • 31
  • 1
  • 7
  • You didn't upload the images. Please edit the question – enrico.bacis Mar 31 '15 at 21:24
  • What command? Check again to make sure you have included the code. – aestrivex Mar 31 '15 at 21:33
  • The command you're using, `plot(x, y, z)` is meant for a parametric curve and doesn't normally have color that varies with `z`, and isn't really what you have anyway. You can add z-color with some effort if you want to, but I suggest you look around for an example plot that looks like it would work for your data and work from there. If you do just want to add color, see here: http://stackoverflow.com/questions/15617207/line-colour-of-3d-parametric-curve-in-pythons-matplotlib-pyplot (but also, at least, plot these as different curves for each trial number). – tom10 Mar 31 '15 at 22:34
  • Thank you! @tom10 I did a scatter plot and colored the graph as I wanted using the example in the link. – Pooja Kapadia Apr 01 '15 at 15:55
  • Great! To stick within the StackOverflow system, the ideal thing then would be to write an answer to your own question and then accept the answer. This way, others could benefit from your solution as well. (If you do this, also post a figure so we can see the difference -- and I can add it into the question and answer as well since you probably don't have the reputation yet to post images.) – tom10 Apr 01 '15 at 16:01

1 Answers1

1

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

enter image description here

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

Community
  • 1
  • 1
Pooja Kapadia
  • 31
  • 1
  • 7
  • Thank you @tom10. Would you please help me with coloring the 3D line plot? I could attach an example of the data I have if required. – Pooja Kapadia Apr 03 '15 at 17:13
  • What you have is a common problem, more data than you can easily view. I'm not convinced that a colored line is the right thing to use and it's not necessarily going to speed things up since your still going to have about 1M things that need to be displayed. The problem is really that you are trying to display so many data points. Also, your scatter plot will look better if you remove the edges of the points: http://matplotlib.org/api/markers_api.html – tom10 Apr 03 '15 at 18:55
  • In general though, I don't want to download data and do your plots for you. Usually the solution to trying to display too many data points is to carefully think through what it is that you really want to show. This can only be done by you. – tom10 Apr 03 '15 at 18:56