0

I have this beautiful code which displays two contour plots. I was wondering if all the colors in the color bar can be displayed in a continuous manner instead of discrete manner? Here is the code below and thank you:

[r,x] = meshgrid(1:0.01:50,-1:0.01:5);
am=(1/4)*(r+(1./r)).*((1-x.^2).^-0.5);
num=2+(  x.*(r+(1./r)) );
dem=(r-(1./r)).*((1-x.^2).^0.5);
G=am.*EA(num./dem);
test=G;
test(G<0)=nan;
test(x==1)=test(x==0);
figure
contourf(log10(r),x,test,'LevelList', [-inf,0,1,2,3,4,5,inf]);
    h=colorbar; 
    set(get(h,'ylabel'),'string',' \gamma P_pL','FontSize',18)
    xlabel('$log_{10}(r)$','Interpreter','latex','FontSize',18)
    ylabel('$D/2\sqrt{M}$','Interpreter','latex','FontSize',18)
    set(gca,'fontsize',18)

    sigpm=1- (2./(r+(1./r)));
    DEm=1+((1-sigpm).*x);
    sig0=sigpm./DEm;

    figure
contourf(sigpm*100,sig0*100,test,'LevelList', [-inf,0,1,2,3,4,5,inf]);
    h=colorbar;
    set(get(h,'ylabel'),'string',' \gamma P_pL','FontSize',18)
    xlabel('$\sigma_\pm$','Interpreter','latex','FontSize',18)
    ylabel('$\sigma_0$','Interpreter','latex','FontSize',18)
    set(gca,'fontsize',18)
    xlim([0 20])
  • `colormap(jet(256))` – obchardon Oct 24 '16 at 06:57
  • I am getting error message: `Undefined function or variable 'EA'.`, can you please post an executable code? You can also add an image to your post. – Rotem Oct 24 '16 at 08:17
  • 1
    If you want more colors, do as @obchardon suggest and call the colormap with a bigger nubmer, but **pleaseeeeee** do not use `jet`, use something like parula, or any or the other nicer colormaps. – Ander Biguri Oct 24 '16 at 08:39
  • Sorry ROtem replace EA(num./dem) with acot(num./dem) – Abed Libnan Haidar Oct 24 '16 at 09:09
  • The answer to my question was just the following v=[0:0.25:5]; figure contourf(log10(r),x,test,'LevelList', v); that way i can display within the same colorbar more colors :) – Abed Libnan Haidar Oct 24 '16 at 09:10

2 Answers2

0

the answer is by adding the following:

v=[0:0.25:5];
figure
contourf(log10(r),x,test,'LevelList', v);
0

Matlab uses a colormap with 64 discrete levels by default. Since we are dealing with computers, nothing will ever be truly continuous, but you can make it seem that way by increasing the number of levels until they are indistinguishable to the human eye.

As suggested by @obchardon and @Ander in the comments, the best way to do this is to call colormap with an argument for the number of levels to use: colormap(parula(256)). You can pick whatever number you want, if 256 is not high enough. At some point you will run into the limits of your screen or printer.

craq
  • 1,441
  • 2
  • 20
  • 39