You should choose the color map carefully, because color transitions along your line might appear drastic if the color map is colorful.Īlternatively, you can change the alpha of each line segment, ranging from 0 to 1. You can use the same procedure to get a specific color for each pair of points. There I showed that you can map the cycle of colors you need to plot your lines to a color map. I recently answered a question with a similar request ( creating over 20 unique legend colors using matplotlib ). Verts = path.interpolated(steps=3).verticesĬolorline(x, y, z, cmap=plt.get_cmap('jet'), linewidth=2) Segments = np.concatenate(, points], axis=1) Lc = mcoll.LineCollection(segments, array=z, cmap=cmap, norm=norm,Ĭreate list of line segments from x and y coordinates, in the correct formatįor LineCollection: an array of the form numlines x (points per line) x 2 (x If not hasattr(z, "_iter_"): # to check for numerical input - this is a hack Optionally specify a colormap, a norm function and a line width Plot a colored line with coordinates x and y Using the colorline recipe you could do the following: import matplotlib.pyplot as plt It's more efficient to use a LineCollection object. Note that if you have many points, calling plt.plot for each line segment can be quite slow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |