I created an intensity-plot (x and y axes are positions, the color of the point gives the intensity) in an external program (igor pro) and included the "bare" plot via the \addplot graphics command into my axis-environment. Now I would like to create a "color-scale"-legend for this plot. The plot is in greyscales, white being no intensity and black being maximum intensity, color changing lineary with intensity.
Unfortunately, I'm not allowed to upload images yet, so I cannot show you what it should look like, so I hope my description is sufficient.
Is there a way to create such a custom legend?
Thans in advance,

here is the plot as it should like:
enter image description here
Creating the axes and labels with pgfplots is no problem, but i also need the colorscale legend.

  • 1
    I upvoted your question, you should now have enough rep to upload the image.
    – Jake
    Commented Sep 4, 2012 at 13:17
  • 1
    Welcome to LaTeX! As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again until you get more rep points.
    – percusse
    Commented Sep 4, 2012 at 13:25
  • Thank you both for "boosting" me, and also for the trick with the workaround :)
    – Janek
    Commented Sep 4, 2012 at 13:41
  • Should black correspond to 0 or 1?
    – Jake
    Commented Sep 4, 2012 at 13:47
  • Black should be 1. I didn't want to post an image of my unpublished work, so I quickly created a new one and obviously used the wrong scaling :) Sorry for that.
    – Janek
    Commented Sep 4, 2012 at 13:59

1 Answer 1


You can activate the colormap simply by calling colormap in the axis options. The default range is 0 to 1, so you wouldn't even need to do adjust it in this case, but usually you would use point meta min=<lower>, point meta max=<upper>.

There are a number of predefined colormaps which are documented in the manual. There is a grayscale colormap which assigns black to the lowest and white to the highest values. In case you want a different mapping, you can create your own using a statement like

colormap={whiteblack}{gray(0cm)=(1); gray(1cm)=(0)}

You can customise the colorbar using the same options that apply to axis environments by passing the options to colorbar style.


    axis equal image,
    axis on top,
    point meta min=0, point meta max=1,
    colormap={whiteblack}{gray(0cm)=(1); gray(1cm)=(0)},
    colorbar style={
        at={(1.1,0)}, % Coordinate system relative to the main axis. (1,1) is upper right corner of main axis.
        anchor=south west,
        height=2/3*\pgfkeysvalueof{/pgfplots/parent axis height}, % Scale the colorbar relative to the main axis
        /pgf/number format/.cd, % Change the key directory to /pgf/number format
        fixed, fixed zerofill, precision=1,
        /tikz/.cd  % Change back to the normal key directory
\addplot graphics [xmin=-1, xmax=1, ymin=-1, ymax=1] {image};

You must log in to answer this question.

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