3

How do I dash specific lines in Tikz that are defined by functions? For example, how would I dash only the black line in the following diagram?

\begin{minipage}{0.48\textwidth}
\begin{tikzpicture}[scale=1.4]
\foreach \a/\Col in {0.5/green,1.2/red, 1/black}
{
\draw[\Col] plot[domain=0:4,variable=\x,samples=90] ({\x},{5.7*\x*(\a*\x^\a)/(1+\x^\a)^2});
}
\foreach \a/\Col in {3/cyan,0.02/magenta, 1/black}
{
\draw[\Col] plot[domain=0:4,variable=\x,samples=90] ({\x},{5.7*(\a*\x^2)/(1+\a*\x)^2});
}
\draw (0,0) rectangle (4,4);
\draw [dotted] (1,0) node[below]{$1$} -- (1,4);
\draw [dotted] (0,1.1) node[left]{$0.5$} -- (4,1.1);
\node at (3.6,-.2) {$v_i$};
\node at (-.2,3.5) [rotate=90] {$b_i$};
\end{tikzpicture}

enter image description here

5

You can do exactly the same thing you did for the colors.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}[scale=1.4]
\foreach \a/\Col/\dashing in {0.5/green,1.2/red, 1/black/dashed}
{
\draw[\Col,\dashing] plot[domain=0:4,variable=\x,samples=90] ({\x},{5.7*\x*(\a*\x^\a)/(1+\x^\a)^2});
}
\foreach \a/\Col/\dashing in {3/cyan,0.02/magenta, 1/black/dashed}
{
\draw[\Col,\dashing] plot[domain=0:4,variable=\x,samples=90] ({\x},{5.7*(\a*\x^2)/(1+\a*\x)^2});
}
\draw (0,0) rectangle (4,4);
\draw [dotted] (1,0) node[below]{$1$} -- (1,4);
\draw [dotted] (0,1.1) node[left]{$0.5$} -- (4,1.1);
\node at (3.6,-.2) {$v_i$};
\node at (-.2,3.5) [rotate=90] {$b_i$};
\end{tikzpicture}
\end{document}
|improve this answer|||||
  • You're the best! – pafnuti Jul 6 '18 at 19:03
5

The two functions for the black curves are identical for \a = 1. One of 1/black in the \foreach list can be removed. The other can be moved outside of \foreach to apply a different line style:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1.4]
\foreach \a/\Col in {0.5/green,1.2/red}
{
  \draw[\Col] plot[domain=0:4,variable=\x,samples=90]
    ({\x},{5.7*\x*(\a*\x^\a)/(1+\x^\a)^2});
}
\foreach \a/\Col in {3/cyan,0.02/magenta}
{
  \draw[\Col] plot[domain=0:4,variable=\x,samples=90]
    ({\x},{5.7*(\a*\x^2)/(1+\a*\x)^2});
}
\draw[dashed] plot[domain=0:4,variable=\x,samples=90]
  ({\x},{5.7*(\x^2)/(1+\x)^2});
\draw (0,0) rectangle (4,4);
\draw [dotted] (1,0) node[below]{$1$} -- (1,4);
\draw [dotted] (0,1.1) node[left]{$0.5$} -- (4,1.1);
\node at (3.6,-.2) {$v_i$};
\node at (-.2,3.5) [rotate=90] {$b_i$};
\end{tikzpicture}
\end{document}

Result

|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.