0

I want to make a color-coded plot in python, but with lines instead of points. I used matplotlib and among others, these lines of code:

color_scheme = plt.get_cmap('spectral')

fig = plt.figure(figsize=(12,10))
gs = gridspec.GridSpec(1, 1)
ax1 = plt.subplot(gs[0])
im1 = ax1.scatter(bin_x, bin_y, c=red, edgecolors='black', marker='o', s=60, lw=1, cmap=color_scheme, vmin=0, vmax=10,zorder=1) 

and I obtained this plot: enter image description here

I want the same plot but to have straight lines instead of points, and the lines to be color coded as the points in the above plot. How can I do this?

cel
  • 30,017
  • 18
  • 97
  • 117
Silviu
  • 749
  • 3
  • 7
  • 17
  • [This](http://matplotlib.org/users/pyplot_tutorial.html) may help you figure it out. – Tammo Heeren Oct 22 '16 at 19:02
  • @TammoHeeren I checked that before, but I don't want to give colors to the lines by hand. I want the colors to be distributed automatically based on a 3rd parameter. For points I can do that using ax1.scatter(), but for lines ax1.plot() is not working. So this is not very helpful, but thanks anyway – Silviu Oct 22 '16 at 19:05
  • It would be helpful to see your code for `plot`. I am pretty sure coloring can be done automatically like you need. – Tammo Heeren Oct 22 '16 at 19:11
  • @TammoHeeren I tried this im1 = ax1.plot(bin_x, bin_y, c=red, edgecolors='black', marker='o', s=60, lw=1, cmap=color_scheme, vmin=0, vmax=10,zorder=1) to obtain a line instead of points (basically to connect the points) but it is not working. – Silviu Oct 22 '16 at 19:13
  • Could you please provide your data? Is it true that all points on the same line have the same color? – Ilya V. Schurov Oct 23 '16 at 00:21
  • This question may be related: http://stackoverflow.com/questions/8500700/how-to-plot-a-gradient-color-line-in-matplotlib – Ilya V. Schurov Oct 23 '16 at 00:21

0 Answers0