0

I am trying to create a contourf plot with a specific color scheme. I defined the colormap as specific matrix values and defined it as such in the code.

cb=[.64 .08 .18;1 0 0;1 .41 .16;1 1 .07;1 1 1;0 1 0;0 1 1;.07 .62 1;0 0 1];

This is my contourf plot script.

figure
contourf(X_w,Z_w,w,'LevelList', [-.1 .1 .2 .4 .6],'LineColor','none')
ylim([0 4])
xlim([-4 20])
xticks([-4 -2 0 2 4 6 8 10 12 14 16 18 20])
yticks([0 .5 1 1.5 2 2.5 3 3.5 4])
pbaspect([3 1 1])
colormap(flipud(cb))
colorbar('Ytick',-.6:.2:.6)
caxis([-.6 .6])

The figure it produces is this. [1]: https://i.stack.imgur.com/b7SNv.png

Everything is correct but the white and the green should be switched. The colorbar is correct and the values are correct but the colormap does not match the colorbar. The green should be white and the white should be green.

Any suggestions?

Garett
  • 1

1 Answers1

0

You might benefit from interpolating between the desired colors, giving your plot a smooth transition between the colors. What could be happening is that the data that you think is 0 is actually just really small and negative. I agree with reza that the plotting data needs to be provided to help further. Until then, try using the interp1 function to redefine the desired map like this:

cb = interp1(1:9,cb,linspace(1,9,128),'pchip');

Notice that I'm only using the number 9 here because that's how many colors you have. The number 128 is just the number of desired output points (interpolated colors).

Dharman
  • 30,962
  • 25
  • 85
  • 135