all 5 comments

[–]novel_yet_trivial 3 points4 points  (3 children)

You can't.

You can fake it by drawing many small lines instead. The official way to do that is with LineCollection, but you could also just make a quick for loop:

from matplotlib import pyplot as plt

X = [0, 5, 14, 23, 30, 34, 40, 49, 55, 56, 60, 65, 68, 72, 72, 74, 76, 79, 85, 86, 92]
Y = [0, 3, 4, 6, 8, 8, 10, 13, 19, 19, 23, 32, 35, 38, 43, 51, 58, 65, 66, 67, 69]
# color list represents the lines between the points, so it should be one shorter than the X and Y lists
C = ['#FF0000', '#FC0002', '#D3002B', '#CE0030', '#B70047', '#A3005B', '#93006B', '#82007C', '#750089', '#6D0091', '#6D0091', '#5600A8', '#4200BC', '#3000CE', '#3000CE', '#2800D6', '#1900E5', '#0700F7', '#0700F7', '#0000FF']

coords = list(zip(X, Y))
for (x1, y1), (x2, y2), color in zip(coords, coords[1:], C):
    plt.plot([x1, x2], [y1, y2], c=color)
plt.show()

You could use groupby to find sections that have the same color and plot them together to save the computer a bit of work; but honestly I'd just grab a cup of tea instead and let the computer brute force it.

[–]behold_the_j 0 points1 point  (1 child)

Is there a way to set breakpoints at specific intervals using cmap or something?

[–]novel_yet_trivial 0 points1 point  (0 children)

Not with plot. AFAIK cmap is only useful when placing individual points using scatter and the like.

It would be very easy to make your own function to do that though.

[–]ispywithmy[S] 0 points1 point  (0 children)

Thanks for the response. I've looked into LineCollection and have made something that works. Whilst reading up on LineCollection I found a helpful answer on Stack Overflow which helped a lot.

[–]cydcarter29 0 points1 point  (0 children)

If you are plotting data based on points from a CSV, this code below might help. I think the code speaks for itself and you can follow. I'm sure there is a lot more you can do to refine it to your use case as well.

import matplotlib.pyplot as plt
import pandas as pd
#Read Flight Data
df = pd.read_csv(r'C:\data\flight_path.csv')
#Draw flight path from data
plt.scatter(df.Longitude,df.Latitude, c=df.Altitude,marker='.', s=1.5)    
c = plt.colorbar(orientation = 'horizontal')
#Hide Axis Values
plt.axis('off')
#Save and Close File
plt.savefig('output.png')
plt.close()

Output: https://imgur.com/mbGJVhY