【问题标题】:How to display all the colors in the color bar into the contourf plot?如何将颜色栏中的所有颜色显示到轮廓图中?
【发布时间】:2016-10-24 04:46:01
【问题描述】:

我有这个显示两个等高线图的漂亮代码。我想知道是否可以以连续方式而不是离散方式显示颜色栏中的所有颜色?这是下面的代码,谢谢:

[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))
  • 我收到错误消息:Undefined function or variable 'EA'.,您能发布一个可执行代码吗?您还可以在帖子中添加图片。
  • 如果您想要更多颜色,请按照@obchardon 的建议执行并使用更大的数字调用颜色图,但pleaseeeeee 不要使用jet,使用类似parula 的东西,或者任何或其他更好的颜色图。
  • 抱歉 ROtem 将 EA(num./dem) 替换为 acot(num./dem)
  • 我的问题的答案就是以下 v=[0:0.25:5];图轮廓f(log10(r),x,test,'LevelList',v);这样我就可以在同一个颜色栏中显示更多颜色:)

标签: matlab plot matlab-figure contourf


【解决方案1】:

答案是添加以下内容:

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

【讨论】:

    【解决方案2】:

    默认情况下,Matlab 使用具有 64 个离散级别的颜色图。由于我们使用的是计算机,因此没有什么是真正连续的,但是您可以通过增加关卡的数量来使其看起来像这样,直到它们对人眼来说无法区分。

    正如 @obchardon 和 @Ander 在 cmets 中所建议的那样,最好的方法是调用 colormap 并带有要使用的级别数的参数:colormap(parula(256))。如果 256 不够高,你可以选择任何你想要的数字。在某些时候,您会遇到屏幕或打印机的限制。

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 2021-01-12
      • 2012-08-29
      • 2022-12-24
      • 2023-03-19
      • 2020-08-23
      相关资源
      最近更新 更多