When I want to plot coordinate data, I know that I can color individual scatter points using defined colors using point meta=explicit. The line segments between two points seem to be colored by an averaged color of the two endpoints.

1) Can I force the color of the line segments to be either the same as the start or endpoints (rather than an averaged color)

2) For black/white plots different gray shades are sometimes hard to distinguish. Is it possible to give the line segments individual styles (i.e. dashed, dotted).

Some background: I want to plot a decreasing curve where different segments represent different phases that need to be distinguishable.


You can tell PGFplots to use the color of one of the end points of the line segments, instead of the average, by setting shader=flat corner (instead of the default shader=flat, which averages the values). In a 2D plot, the line will have the color of the previous point, but in a 3D plot, it is not defined which point influences the line colour, so you would have to be a bit careful in that case.

    scatter, % To colour the points
    point meta=explicit, % To be able to specify the column for the colours
    shader=flat corner % To use the color of one point for the line segment
\addplot [
    mesh,   % Colour the lines
] table [meta=phase] {
time value phase
1 5 1
3 15 2
7 14 3
10 7 3
12 1 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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