1

This question already has an answer here:

I want to "draw[]" a color line starting in green, ending in blue and a transition between green and blue in a smooth continuous fashion. For example in tikz/pgf plots we can use a command such as:

\shade[bottom color=gray, top color=green] (D)--(O)--(B);

to color a triangle with gray and green with a smooth (gradient) transition.

A more specific example is shown in this figure generated with gnuplot, but I do not want to plot a function, and I do not want axes. I just want to draw[] a line or an arc. In other words, I want to "shade[]" a curve in a rainbow coloring.

smooth color on curve

This is not a repeated question: I have seen these posts with similar questions: coloring edge segments with different colors

and also: plotting a curve with different colors

That is not what I want.

Is there a function in TikZ or PGS (no pstricks or metapost please) that do this?

Thanks.


Update:

Here is my poor man solution:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.11}


    \begin{document}


    \begin{tikzpicture}
      \coordinate (O) at (0,0);
      \foreach \t in {0.,0.01,...,1}
      {
      \coordinate (A) at (\t, \t);
      \def\scl{20}
      \pgfmathsetmacro\s{\scl*\t}
      \draw[color=blue!\s!green]  (A) circle (0.1mm);

      }

    \end{tikzpicture}

    \end{document}

and here the plot:

enter image description here

The main problem here is that the curve is hard coded. So, for another curve, I would need a new code.

I will work on creating a macro for a general path. Any ideas? Thanks.

marked as duplicate by OSjerick, Kurt, user13907, Werner, Paul Gaborit tikz-pgf Nov 21 '15 at 7:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Section 4.7.6 of the pgfplots documentation shows how to define your own colormap, but you need to take slightly different approaches to apply the map to symbols or lines.

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[colormap={greenblue}{rgb255(0cm)=(0,0,255); rgb255(1cm)=(0,255,0)}]
    \addplot+[scatter,scatter src=x,samples=50]{sin(deg(x))};
    \addplot[mesh,ultra thick,point meta=x,samples=50]{cos(deg(x))};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • This is good with pgfplots but I need to draw a segment form (A) to (B). I am uneasy about the \begin{axis} ... \end{axis} environment because I have not been able to align the axis outside of this scope. I believe I can remove the axis, but integrating this "axis" environment with TiKz has been hard for me. Thanks – Herman Jaramillo Nov 20 '15 at 23:34
  • Please see this question that I posted in Nov 15: tex.stackexchange.com/questions/278357/… Since, at the moment, I have not been able to align tikzpicture[] axis with axis[] "axis" I prefer to stay away from the "axis[]" environment. Thanks. – Herman Jaramillo Nov 20 '15 at 23:39

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