5

My code so far

\usepgfplotslibrary{colormaps}
\usetikzlibrary{pgfplots.colormaps}
\pgfplotsset{compat=1.9}
\pgfplotsset{
/pgfplots/colormap={bright}{rgb255=(0,0,0) rgb255=(78,3,100) rgb255=(2,74,255)
    rgb255=(255,21,181) rgb255=(255,113,26) rgb255=(147,213,114) rgb255=(230,255,0)
    rgb255=(255,255,255)}

I've just copied this code from the manual. But how can I now tell my plot to use this colormap?

\begin{figure}
\centering
\begin{tikzpicture}
\pgfplotstableread{Plots/dat.txt} \datA
\begin{axis}[
axis y line*=left,
axis x line*=top,
ylabel near ticks,
xlabel near ticks,
xlabel=Current in A,
ylabel=Voltage in V,
every x tick label/.append style = {font=\footnotesize},
every y tick label/.append style = {font=\footnotesize},
]
\addplot [mark=none] table [x index = 0, y index = 1] from \datA ; % ,
\end{axis}
\end{tikzpicture}
\end{figure}

The plot is created correctly but all lines are just black.

1

1 Answer 1

5

When you do \addplot [mark=none] ..., the effect is that mark=none completely overwrites any style given by the active cycle list. That means in turn that the default line style of TikZ is used, which is just a black line. You want \addplot +[mark=none], where the + indicates that mark=none is appended to the style given by the cycle list.

That is just part of the answer though. In the code you show you have only defined a color map, you haven't actually used it. Add colormap name=bright to the axis options to activate it. But the colormap doesn't directly influence the style of line plots, in order to pick colours from the colormap for line plots, add for example cycle list={[of colormap]} to the axis options. Because the bright map you defined has eight colours, this cycle list will get eight colours as well.

If you want a given number of equally spaced samples from the colormap, you can use e.g. cycle list={[samples of colormap={20} of bright]} to get 20 samples (you don't have to specify colormap=bright in this case). You can also get non-equally spaced samples, by using e.g. cycle list={[colors of colormap={0,300,600,1000}]}. You supply a list of values between 0 and 1000, where 0 is the start of the map, and 1000 is the end.

All this colormap vs. cycle list stuff is described in the pgfplots manual, at the end of section 4.7.7 Cycle Lists – Options Controlling Line Styles, page 219. (In the manual for version 1.16 of pgfplots, dated 2018-3-28.

enter image description here

\documentclass{scrartcl}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps} 
\pgfplotsset{compat=1.9}
\pgfplotsset{
colormap={bright}{rgb255=(0,0,0) rgb255=(78,3,100) rgb255=(2,74,255)
    rgb255=(255,21,181) rgb255=(255,113,26) rgb255=(147,213,114) rgb255=(230,255,0)
    rgb255=(255,255,255)}
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
axis y line*=left,
axis x line*=top,
ylabel near ticks,
xlabel near ticks,
xlabel=Current in A,
ylabel=Voltage in V,
every x tick label/.append style = {font=\footnotesize},
every y tick label/.append style = {font=\footnotesize},
colormap name=bright, % activate the defined colormap
cycle list={[of colormap]},
every axis plot/.append style={mark=none,ultra thick} % set options for all plots
]
\addplot {x};
\addplot {x+1};
\addplot {x+2};
\addplot {x+3};
\addplot {x+4};
\addplot {x+5};
\addplot {x+6};
\addplot {x+7}; % white, so not visible
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
8
  • 1
    Thanks for the answer. Really helped a lot. I've already looked at the doc but I wasn't able to figure out what to define inside the axis-block. Another question. When I write cycle list={[samples of colormap={20} of bright]} and I doesn't define the map via \pgfplotsset I get an error, that the argument bright ist not a valid colormap.
    – Steradiant
    Commented Jul 11, 2018 at 13:42
  • @vogs Well yes. That colormap isn't defined by default, so naturally you can't sample from it. Commented Jul 11, 2018 at 13:50
  • I see. But honestly, none of them looks really nice to me. I would prefer some kind of 'rainbow' colors. For me e.g. this could be the color scheme 'hot' from the manual. But if I use 'hot' but then the colors repeat every 3 lines.
    – Steradiant
    Commented Jul 11, 2018 at 14:05
  • @vogs So add the definition of the hot colormap (instead of bright), and use for example cycle list={[samples of colormap={10} of hot]}. Then the colours reapeat every 10 lines. Change the number (10) as you see fit. Commented Jul 11, 2018 at 14:32
  • I have now just following two lines: cycle list={[samples of colormap={8} of hot]}, every axis plot/.append style={mark=none}. But the 8 colors are so close. Like yellow, dark yellow, light orange. One can't distinguish them.
    – Steradiant
    Commented Jul 12, 2018 at 19:38

You must log in to answer this question.

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