Open Atcold opened 2 years ago
With the PS/PDF operations that TikZ operates, you cannot alter the line properties midway. If it starts in one config until the path is "inked" you are stuck with it. What you want to do here is to change the colors of the black line which is not possible.
If you chop it up like you did here then you would obviously lose all the nice curvy path drawing. So the remaining option is to reveal a shading via the path ala https://tex.stackexchange.com/questions/134283/tikz-shading-a-path-without-any-filling
Apparently more people chimed in and there are good answers compared to my neanderthal answer (percusse). So you might want to check it.
Or you draw the thick line as a surface and let pgfplots handle the mesh coloring but that requires more work on parametrization of the surface.
Linking related/identical question on TeX-SX, which has received an accepted answer using three extra mesh plots with manually shifted samples. https://tex.stackexchange.com/q/664854
Theoretically it's possible to provide a new option smooth mesh
, but that need a deep understanding about \pgfplotsplothandlermesh
, the plot handler beneath mesh
option.
It seems the key is to automatically make up line joins. A non-trivial soft path manipulation task.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=3, line width=15pt]
% miter line join
\draw (0,0) -- (1,0) -- (1,1);
% no line join
\begin{scope}[xshift=1.5cm]
\draw[blue] (0,0) -- (1,0);
\draw[red] (1,0) -- (1,1);
\end{scope}
% made-up line join
\begin{scope}[xshift=3cm]
% target to fill, for debug
% \draw[draw opacity=.3] (0,0) -- (1,0) -- (1,1);
\fill[blue]
(0,0) ++(0pt,-2.5pt) -- ++(0pt,5pt) -- ++(1cm-2.5pt,0) -- ++(5pt,-5pt) -- cycle;
\fill[red]
(1,0) ++(-2.5pt,2.5pt) -- ++(5pt,-5pt) -- ++(0,1cm+2.5pt) -- ++(-5pt,0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}
Theoretically it's possible to provide a new option
smooth mesh
, but that need a deep understanding about\pgfplotsplothandlermesh
, the plot handler beneathmesh
option.
Would anyone be interested in adding this? As you pointed out, I was already given a hack to handle this quirk.
I'd like a smooth 1d mesh, line the black curve, but coloured. All I'm able to get is the collection of rectangles shown in the figure below…