6
votes

I am trying to produce a figure in Matlab suitable for publication, and I need some help with the colorbar.

My data ranges from -20 to 30, but I want the colorbar to focus on -15 to 15, with arrows at each end to represent values outside that range.

I have tried using the class "pointyColorbar" (http://www.mathworks.co.uk/matlabcentral/answers/48773) but it doesn't produce the required output. Ideally, I would like the colorbar to look like the one below, but using my custom colormap.

Can anyone help me out with this? Sorry if I haven't asked the question right - I am new to this!

enter image description here

As requested, below is what I currently have for my colorbar (cmap is my custom color map):

cmap=precipanomcolourmap(7,7)
colormap(cmap)
caxis([-20 30])
cb=colorbar('location','southoutside');
set(get(cb,'title'),'string','Average annual precipitation anomaly (%)','FontWeight','bold');
set(cb,'XTick',[-17.5 -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 17.5]);
xlim(cb,[-17.5 17.5]);

This gets me a rectangular colorbar below my figure ranging from -17.5 to 17.5. The values outside of this are marked using the same colour as the +/- 15-17.5 range.

When I tried the pointyColorbar class, I replaced the cb=colorbar('location','southoutside'); line with cb=pointyColorbar(15,-15,'location','southoutside'). It may well be that I need to play around with how to use the pointyColorbar class, but I don't understand the code well enough to know how to get it to look how I want it.

1
Could you show us what you have done so far in MATLAB?m_power
I have added some code above :)emmalgale
What version of MATLAB are you using? I saw that the functions isrow and iscolumn in the pointyColorbar are only available from MATLAB R2011a. Also, the poly2mask function is available in the Image Processing Toolbox, so the class won't work if you don't have that toolbox.m_power
I am using MATLAB R2013a, and I also have the Image Processing Toolbox. My MATLAB license is through my university, so I have quite a lot of the toolboxes. When I did use the pointyColorbar class, it basically had the colorbar in a rectangular box with some arrows within it, but it didn't look right. Not sure if I can post the image of it though.emmalgale
The class seem to works for loading images, I don't know if it will work with contour function.m_power

1 Answers

0
votes

About the poining issue, I think your answer is as the bottom of this page:

http://www.mathworks.com/matlabcentral/answers/48773

and about the colorbar limits, I think you are looking for something like:

set(gca, 'CLim', [cLow, cHigh]);

before dislaying the colorbar.

('cLow' and 'cHigh' are the limits you want for the colorbar).

Take a look at this: http://www.mathworks.com/matlabcentral/newsreader/view_thread/163344