I would like to get the color definition from a sample of colors in a pgfplots colormap using for example the RGB model. When I choose colormap/bluered with colorbar style={samples=10} I need to have the xcolor definition of those particular colors to plot different curves. Is there an automatic way to generate these color specifications from the colormap definition?

  • @Jake I would like to have the color values and show a sampled color bar with a scale. I will add an example to the question. – Miguel de Val-Borro Jul 30 '13 at 21:17
  • @Jake That's right, each plot has the same color in the whole domain. – Miguel de Val-Borro Jul 30 '13 at 21:41

You can make a colour from the colormap available as mapped color by calling the macro \pgfplotscolormapdefinemappedcolor{<value>}, where <value> is a number between 0 and 1000 that is mapped linearly into the current color map.

In order to use different colours for different plots, this macro needs to be called within execute at begin plot visualization, otherwise all the plots end up with the same colour:


    colorbar sampled,
    colorbar style={samples=6},
    point meta min=0,
    point meta max=10

\addplot [
    execute at begin plot visualization={%
    mapped color,
] {#1*sin(x)};
  • Thanks a lot. I get this error when I compile this example on Texlive 2012:! Undefined control sequence. \pgfplotscolormapdefinemappedcolor ...formedrange ] [1.0] {#1} {\pgfkeysvalu... – Miguel de Val-Borro Jul 30 '13 at 22:20
  • @MigueldeVal-Borro: What version of PGFPlots are you using? – Jake Jul 30 '13 at 22:22
  • pgfplots 2011/12/29 v1.5.1 – Miguel de Val-Borro Jul 30 '13 at 22:24
  • @MigueldeVal-Borro: Ah, yes, that's pretty dated. I would recommend updating to the current version (1.8) – Jake Jul 30 '13 at 22:25
  • Thanks, however the pgfplotscolormapdefinemappedcolor does not work for me when I read the data coordinates from a file like \addplot table[x index=0,y index=1] {datafile.dat}; – Miguel de Val-Borro Jul 31 '13 at 14:55

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.