【问题标题】:second y-axis on pcolor plotpcolor 图上的第二个 y 轴
【发布时间】:2012-04-01 14:45:30
【问题描述】:

是否可以用 2 个 yaxis 制作 pcolor 图?

考虑以下示例:

clear all
temp =  1 + (20-1).*rand(365,12);
depth = 1:12;
time =1:365;

data2 = 1 + (60-1).*rand(12,1); 
time2 = [28,56,84,124,150,184,210,234,265,288,312,342];

figure;
pcolor(time,depth,temp');axis ij; shading interp
hold on 
plot(time2,data2,'w','linewidth',3);

我希望将第二个数据集放置在自己的 y 轴上,而不是在同一 y 轴上绘制第二个数据集。这可能吗?

【问题讨论】:

    标签: matlab colors plot


    【解决方案1】:

    您需要在 pcolor 轴的顶部添加额外的轴,匹配它们的位置,然后绘制。您可以在顶部 (X) 和右侧 (Y) 设置轴位置。如果 X 轴与 LINKAXES 匹配,请不要忘记链接它们。

    pcolor(time,depth,temp');axis ij; shading interp
    ax1 = gca;
    %# new axes with plot
    ax2 = axes('position',get(ax1,'position'),'color','none');
    set(ax2,'YAxisLocation','right', 'XAxisLocation','top')
    hold on
    plot(ax2,time2,data2,'w','linewidth',3);
    hold off
    linkaxes([ax1 ax2], 'x');
    

    【讨论】:

      【解决方案2】:

      我不确定你的意思。 如果您想要相同的轴但不同的 y 值,请尝试plotyy。如果您想要两个不同的轴,请尝试使用命令subplot

      【讨论】:

      • 从你写的内容来看,我更多的是寻找涉及 plotyy 的解决方案,但我无法让 plotyy 使用 pcolor 绘图。
      猜你喜欢
      • 2017-01-15
      • 1970-01-01
      • 2023-04-07
      • 2019-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多