5

I want to draw a path in tikz whose local color is a function of position. Here are two examples of what I have in mind:

colored ptahs

I found the answers from Path following color gradient in TikZ very instructive. However, in the examples the used colormaps are simple gradients. I need to define a more complicated colormap. Is there a simple way to do this? Or are there even pre-defined colormaps? Or should I use pgfplots?

7

pgfplots offers something on these lines. An example from the manual:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=none]
\addplot[mesh,samples=1000,domain=-4*pi:4*pi,line width=2pt] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • 2
    This color map is so much simpler than the shown in the question. – osjerick Dec 11 '13 at 19:42
2

I was able to produce the figure with the non-trivial colormap by computing the coordinates and colors externally and using the meta point information in pgfplots. Here is the code:

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

\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}

\begin{scope}[yshift=0cm]
    \draw[->, >=latex, color=black, line width=1.0pt, cap=round] (0.00, 0.00) -- (3.5, 0.00);
    \draw[->, >=latex, color=black, line width=1.0pt, cap=round] (0.00, -1.00) -- (0.0, 1.00);
    \begin{axis}[x=3cm, y=1cm, ticks=none, axis lines=none, colormap/jet, anchor=origin]
        \addplot[mesh, ultra thick, point meta=\thisrow{c}, shader=interp] table[x=t, y=x] {sine_wave_high_res_01.dat};
    \end{axis}
\end{scope}


\begin{scope}[xshift=5.0cm, yshift=0cm]
    \draw[->, >=latex, color=black, line width=1.0pt, cap=round] (-1.10, 0.00) -- (1.25, 0.00);
    \draw[->, >=latex, color=black, line width=1.0pt, cap=round] (0.00, -1.10) -- (0.0, 1.10);
    \begin{axis}[x=0.2cm, y=0.2cm, ticks=none, axis lines=none, colormap/jet, anchor=origin]
        \addplot[mesh, ultra thick, point meta=\thisrow{c}, shader=interp] table[x=x, y=y] {spiral_high_res_01.dat};
    \end{axis}
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

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.