20

Is it possible to make pgfplots use a predefined color map while plotting multiple lines, I currently have 9 samples that I want to plot, but don't want to type different colors for each one. Right now they are all showing up as black. Let me know if this is possible, thanks!

30

You can use cycle list name=<list>. there are few pre-defined lists --

  1. color (from top to bottom)
  2. exotic
  3. black white
  4. mark list
  5. mark list*
  6. linestyles
  7. linestyles*
  8. auto

If you want you can create your own list like

\pgfplotscreateplotcyclelist{mycolorlist}{%
blue,every mark/.append style={fill=blue!80!black},mark=*\\%
red,every mark/.append style={fill=red!80!black},mark=square*\\%
brown!60!black,every mark/.append style={fill=brown!80!black},mark=otimes*\\%
black,mark=star\\%
blue,every mark/.append style={fill=blue!80!black},mark=diamond*\\%
red,densely dashed,every mark/.append style={solid,fill=red!80!black},mark=*\\%
brown!60!black,densely dashed,every mark/.append style={
solid,fill=brown!80!black},mark=square*\\%
black,densely dashed,every mark/.append style={solid,fill=gray},mark=otimes*\\%
blue,densely dashed,mark=star,every mark/.append style=solid\\%
red,densely dashed,every mark/.append style={solid,fill=red!80!black},mark=diamond*\\%
}

and use it as cycle list name=mylist.

Code (taken from pgfplots manual):

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
stack plots=y,stack dir=minus,
cycle list name=color list]
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\addplot coordinates {(0,1) (0.5,1) (1,1)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • @cmhughes For the code given above, yes, it is the expected output (same in manual also) :) – user11232 Apr 7 '14 at 23:48
  • oh, I see that you didn't actually use the cycle list that you created :) – cmhughes Apr 7 '14 at 23:50
  • @cmhughes No, It is just color list which is pre-defined. :) – user11232 Apr 7 '14 at 23:57
  • auto seems to be the default. As usual the problem with automatic list is that eventually they hit yellow. :) – alfC Jan 11 '18 at 0:09
5

With the release of PGFPlots v1.13 it is much easier to define cycle lists, because now there exist much more possibilities. For example cycle lists can be combined from other cycle lists. With that you can define your "default" color cycle list and then combine it with others to fit certain requirements.

Here you can see an example using the cycle multiindex* list key. For more have a look at section 4.7.7 on page 194 of the PGFPlots manual.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
    \usetikzlibrary{
        pgfplots.colorbrewer,
    }
    \pgfplotsset{
        % define a `cycle list' for marker
        cycle list/.define={my marks}{
            every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=*\\
            every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=square*\\
            every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=triangle*\\
            every mark/.append style={solid,fill=\pgfkeysvalueof{/pgfplots/mark list fill}},mark=diamond*\\
        },
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            % load a color `cycle list' from the `colorbrewer' library
            cycle list/RdGy-6,
            % define fill color for the marker
            mark list fill={.!75!white},
            % create new `cycle list` from existing `cycle list's and an
            cycle multiindex* list={
                RdGy-6
                    \nextlist
                my marks
                    \nextlist
                [3 of]linestyles
                    \nextlist
                very thick
                    \nextlist
            },
            samples=3,
            legend entries={0,...,20},
            legend pos=outer north east,
        ]
            \addplot {x};
            \addplot {x-1};
            \addplot {x-2};
            \addplot {x-3};
            \addplot {x-4};
            \addplot {x-5};
            \addplot {x-6};
            \addplot {x-7};
            \addplot {x-8};
            \addplot {x-9};
            \addplot {x-10};
            \addplot {x-11};
        \end{axis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

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.