Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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,
John

edit:
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.

share|improve this question
1  
I upvoted your question, you should now have enough rep to upload the image. –  Jake Sep 4 '12 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 Sep 4 '12 at 13:25
    
Thank you both for "boosting" me, and also for the trick with the workaround :) –  Janek Sep 4 '12 at 13:41
    
Should black correspond to 0 or 1? –  Jake Sep 4 '12 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 Sep 4 '12 at 13:59
add comment

1 Answer 1

up vote 4 down vote accepted

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.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis equal image,
    enlargelimits=false,
    axis on top,
    colorbar,
    point meta min=0, point meta max=1,
    colormap={whiteblack}{gray(0cm)=(1); gray(1cm)=(0)},
    colorbar style={
        title=Intensity,
        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};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
That's perfect! Thank you so much! –  Janek Sep 4 '12 at 14:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.