TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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
share|improve this answer
How can I add such a plot to the legend with the marker as icon (instead of the default tiny mesh symbol)? I created a question for that -> tex.stackexchange.com/questions/33535/… – dcn Nov 3 '11 at 11:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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