5

If we assume 2 curves in the same figure. So to distinguish between them, we set a different colors for them. However, can we change the form not the color ? In other words, if we assume that we have 5 curves, and to distinguish between them, we set a specific form for each of them. Any help?

By the way, you can read the code below (taken from this link).

\documentclass{article}
\usepackage{tikz,pgfplots}

\begin{document}
   \begin{tikzpicture}
        \begin{axis}[%
            axis x line=bottom,
            axis y line=left,
            xlabel=$X$,
            ylabel=$Y$,
            legend pos= south east]
            \addplot[mark=none,blue,thick] coordinates {(0.1, 0.003) (0.5, 0.005) (2, 0.4) (5, 1)};
            \addplot[mark=none,red,thick] coordinates {(0.1, 0.2) (0.5, 0.5) (2, 0.1) (5, 1.4)};
            \legend{$Y_1$,$Y_2$};
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    You mean for example one solid line and one dashed line? – Torbjørn T. Nov 11 '13 at 21:34
  • Exactly! one solid line, one dashed line, one with other form.. i need at least 4 or 5 forms :) Thank you very much for your response! – Christina Nov 11 '13 at 21:36
4

There are several line styles available in pgfplots. The default is a solid line, other options include dashed, dotted, dashdotted, and dense and loose versions of the same, e.g. densely dashed and loosely dashed. See section 4.7.2 Line Styles of the pgfplots manual.

You can also specify your own pattern with dash pattern, for example dash pattern=on 10pt off 2pt on 5pt off 6pt.

Add these to the options of the \addplot, just like the colours. For example:

\documentclass{article}
\usepackage{tikz,pgfplots}

\begin{document}
   \begin{tikzpicture}
        \begin{axis}[%
            axis x line=bottom,
            axis y line=left,
            xlabel=$X$,
            ylabel=$Y$,
            legend pos=north west]
            \addplot[mark=none,solid,thick] coordinates {(0,0) (1,0.5)};
            \addplot[mark=none,dashed,thick] coordinates {(0,0) (1,1)};
            \addplot[mark=none,dotted,thick] coordinates {(0,0) (1,1.5)};
            \addplot[mark=none,dashdotted,thick] coordinates {(0,0) (1,2)};
            \addplot[mark=none,dash pattern=on 10pt off 2pt on 5pt off 6pt,thick] coordinates {(0,0) (1,2.5)};
            \legend{$Y_1$,$Y_2$,$Y_3$,$Y_4$,$Y_5$};
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

2
  • Thank you very much!!! do you know one more form ? i need only one more form :) thank's in advance! – Christina Nov 11 '13 at 21:44
  • 1
    @Liszt I added a custom one, but as I mention there are densely dashed/densely dotted etc. as well. – Torbjørn T. Nov 11 '13 at 21:49

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.