Yes, I know there are several topics about, but no one referred to my case. While colormap
seems works only with plots, how can I draw a multicolor curve with smooth gradient? This is my attempt:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{booktabs}
\usepackage{amsmath,amssymb,amsfonts,systeme,mathtools}
\usepackage{pgfplots}
\usepackage{float}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
ticks=none,
grid=none,
xmin=0,xmax=100,
ymin=0,ymax=100,
axis lines = middle,
set layers,
xlabel={$t$},ylabel={$T$},
x label style={at={(1,0)},right},
y label style={at={(0,1)},above},
colormap={redblue}{rgb255(0cm)=(255,0,0); rgb255(1cm)=(0,0,255)}
]
\draw [ultra thick] (20,90) to[out=270,in=110] (25,60) to[out=335,in=115] (35,45) to[out=0,in=180] (70,45) to[out=305,in=150] (90,20);
\node[inner sep=0pt, label={[outer sep=-2pt]45:A}] at (20,90) {} ;
\node[label={[outer sep=-2pt]45:B}] at (25,60) {} ;
\node[label={[outer sep=-2pt]45:C}] at (35,45) {} ;
\node[label={[outer sep=-2pt]45:D}] at (70,45) {} ;
\node[label={[outer sep=-2pt]45:E}] at (90,20) {} ;
\addplot[only marks, mark options={solid,draw=green,fill=green}]
coordinates {
(20,90) (25,60) (35,45) (70,45) (90,20)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Can you help me?
Thank you in advance
Best Answer
As you said,
colormaps
works withplot
s. In your code there is indeed aplot
, but only for plotting the marks and hence not the line. This one is drawn with the\draw
command inside the axis. Therefore, you have to add a gradient color to your line.Gradient with two colors
For instance, using the solution by Mark Wibrow to How to draw an arrow with two colors? you can add a color gradient using
\path
and the definedshading path
option intikset
. Then withleft color=<color>
andright color=<color>
(ortop color=<color>
andbottom color=<color>
) you have a gradient with only two colors.Output:
Code:
Gradient with multicolors
For a multicolor gradient there is also a possibility. The aforementioned solution pass a gradient of two colors to the line color with the commands of the Shading library (Chapter 69, p.737). Therefore, if we are able to pass a multicolor gradient to Mark Wibrow´s solution, we have it done. Thankfully, Mark Wibrow gives us also the solution in the answer to How to draw gradient arrows with Tikz. Just combining both of them we can set a desired multicolor gradient.
Output with
shading1
:Output with
shading2
:Output with
shading3
:Code: