0

I am plotting a list of points from a file with pgfplots and would like the color of the marks to vanish (color gradient from green to white) in their row order.

I did not manage to find the metric used by colormap to assign a color to a mark. From the following MWE, it seems it uses the y-value. Instead, I would like it to use the row index (or a kind of curvilinear coordinate).

\documentclass[tikz]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[]
\addplot[scatter, colormap={}{color(0cm)=(green); color(1cm)=(green!0)}]%
table {
   x y
   -0.25    0.95
    0.37    0.83
    0.76    0.18
    0.55    -0.53
   -0.36    -0.39
    0.34    -0.62
    0.78    -0.10
    1.0      1.0
  };
\end{axis}
\end{tikzpicture}

\end{document}

In short, I would like the gradient to be monotonous, from white at the beginning to green at the end of the curve instead of white-green-white.

enter image description here

Edit The solution here does not seem to work:

\addplot+[mesh,shader=interp,colormap={}{color(0cm)=(green); color(1cm)=(red)}]%
  ...

returns red -> green -> red instead of a simple gradient:

enter image description here

2

1 Answer 1

1

use scatter src to specify what is the source of the color. Since you haven't used any, it's using y value as the color, which is why your upper points are light and lower points are dark. One option is to add a column to your data as an index, or simply use:

\addplot[scatter, colormap={}{color(0cm)=(green); color(1cm)=(green!0)}, scatter src = \thisrow{x}]%

enter image description here

1
  • Thank you, I added an extra column with the row index.
    – anderstood
    Commented Sep 1, 2022 at 9:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .