I use cycle list name=exotic as coloring for my plots. I am looking for a way, either to use a number referring to a color (index from the exotic list), or a way to get the color of a labelled plot.

Here are an example of what I tried :

    \pgfplotsset{cycle list name=exotic}
    \begin{axis}[enlarge x limits=false]
        \addplot+[thick, no marks, domain=0:360, samples=50, forget plot]  {sin(x)};
        \addplot+[thick, no marks, domain=0:360, samples=50]  {cos(x)};
        \legend{plot 1, plot 2}

But of course, the first plot is "forgotten" and therefore not taken into account for the color code. (Accessing the color of a labelled plot would probably be useful, even if it exist a simpler solution.)


I'll give here a general example how you can do this. The trick is to first define a colormap and then to convert this colormap to a cycle list. For other stuff you can then access the colors of the colormap with the new feature index of colormap which was introduced in PGFPlots v1.13.

For more details have a look at the comments in the code.

        % define a colormap that contains the colors you
        % want to use in the `cycle list'
        colormap={my colormap}{
        % define some other `cycle list's to later combine them if you need
        % I will use here some predefined ones for simplicity
    % now create a `cycle list' from that colors
    \pgfplotscreateplotcyclelist{my color cycle list}{
        [of colormap=my colormap]
            % some options to better visualize the result
            stack plots=y,
            every axis plot/.style={
                line width=2pt,
            % define here the `cycle list' you need
            cycle multiindex* list={
                my color cycle list
                [3 of]mark list
            % add some plots
            \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)};

            % if you want to use the color of the 2nd plot you can do this via
            % (you need index 1 here, because the index starts at 0)
            \node [index of colormap=1,anchor=south]
                at (0.25,2) {I am the 2nd color};

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.