Clear Filters
Clear Filters

Contourcbar acting weird when using caxis on contourfm plot?

1 view (last 30 days)
Hello!
I'm making some plots with contourfm and I'm trying to use caxis to set the color limits to a specific range.
f = figure(1)
axesm ('mercator','MapLatLimit',latlim,'MapLonLimit',lonlim)
contourfm(Y,X,Z)
caxis([0 2000])
contourcbar
If the values of my data (Z) go up to 2000, then the colorbar produced is fine and the colors are correctly distributed in the colorbar. But if my data doesn't go up to 2000, let's say the maximum it's 1000, then the colorbar distributes all the colors until 1000, and between 1000 and 2000 it's all full of the same color.
I tried looking for an answer but the only subject I found similar to this is this other question. However, I have no idea how to apply that on my code to try that out.
I'm using matlab R2015b.
Please let me know if you need more info of the code I'm using, or if you need a screenshot of the colorbar I'm getting.
Thanks in advance!

Accepted Answer

Amy Haskins
Amy Haskins on 3 May 2016
contourcbar reflects the discrete nature of contour plots. When you contoured your data using contourfm, each contour level has a fill color representing values between 2 contour levels. When you change the caxis, you haven't changed the contour levels in your data. The color at the top of the contour bar represents any values greater than the highest contour level. When you extend the caxis limits, that interval gets larger and hence the band gets wider.
If you use colorbar to add a color bar instead of contourcbar you will see something that might look more like your expecting where the colors vary smoothly, but it's much harder to know the exact limits of each contour interval.
I think the trick is to specify the contour levels in your call to contourfm. You'll still need to set the CLim of the axis.
f = figure(1)
ax = axesm('mercator','MapLatLimit',latlim,'MapLonLimit',lonlim)
contourfm(Y,X,Z,0:100:2000)
ax.CLim = [0 2000];
contourcbar

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!