17

Is it possible to draw thick curve between (2,2) (4,3). Remaining portion must be thin.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw [blue] plot [smooth] coordinates {(0,0) (2,2) (4,3) (5,5) (0,10)};
\end{tikzpicture}
\end{document}

1 Answer 1

16

1)

Here is a simple solution (via clip action) for your specific MWE.

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\def\mycoordinates{(0,0) (2,2) (4,3) (5,5) (0,10)}
\begin{document}
\begin{tikzpicture}
  \draw [blue,thin] plot [smooth] coordinates {\mycoordinates};
  \begin{scope}
    \clip (0,2) rectangle (5,3);
    \draw [red,very thick] plot [smooth] coordinates {\mycoordinates};
  \end{scope}
\end{tikzpicture}
\end{document}

2)

Here is more general solution (via show path construction decoration).

The style between style requires three arguments: {<coord#1>}{<coord#2>}{<special style>}. The special style is applied on segments between coord#1 and coord#2.

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usepackage{ifthen}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\newcounter{pos}
\tikzset{
  initcounter/.code={\setcounter{pos}{0}},
  style between/.style n args={3}{
    postaction={
      initcounter,
      decorate,
      decoration={
        show path construction,
        curveto code={
          \addtocounter{pos}{1}
          \pgfmathtruncatemacro{\min}{#1 - 1}
          \ifthenelse{\thepos < #2 \AND \thepos > \min}{
            \draw[#3]
            (\tikzinputsegmentfirst)
            ..
            controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
            ..
            (\tikzinputsegmentlast);
          }{}
        }
      }
    },
  },
}
\begin{document}
\begin{tikzpicture}
  \draw [
  style between={2}{4}{red,thick},
  style between={5}{8}{green,very thick},
  blue,thin] plot [smooth]
  coordinates {(0,0) (4,0) (2,4) (1,1) (3,1) (1,3) (0,1) (1,0) (4,4)};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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