1
$\begingroup$

I'm working with a ListPlot of several points.

I'd like to plot the points with a gradient of colors (for example, from blue to red) following their position in the x-axes.

For example:

x = {0,1,2,3,4,5,6,7,8,9,10};
y = {1,3,5,3,1,4,7,10,5,0,1};
data = Transpose@{x, y};
myplot = ListPlot[data]

That plots appears as:

enter image description here

I'd like to have a continuous change of the markers' colors, from blue tonalities in the left (near to x = 0) to red tonalities in the right (near x = 10).

What command should I use inside the ListPlot?

Thank you very much for your time!

$\endgroup$
3
$\begingroup$

For ListPlot, one easy way to go is to wrap the data points in Style:

ListPlot[
    Map[
        Style[#, Blend[{Blue, Red}, #[[1]] / 10.]]&,
        data
    ]
] 

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.