【问题标题】:Two y-axes plot for multiple data set in MatlabMatlab中多个数据集的两个y轴图
【发布时间】:2014-12-23 12:14:44
【问题描述】:

我正在尝试在 Matlab 中创建两个 y 轴图。 我有两组数据,每组都有三个相似类型的图。当我试图绘制它时,右侧 y 轴上的缩放会变得混乱。我将不胜感激。

X = [50, 100, 200, 400];

YSKL_Temporal_WOFAE    = [3.2000       2.3354      1.9428          1.7658];
YSKL_Spatial_WOFAE     = [0.9225       0.9724      1.0986          1.1770];
YSKL_Spatial_WithFAE   = [0.2635       0.1653      0.1513           0.1618];

YMSRE_Temporal_WOFAE    = [0.3559       0.3027    0.2733          0.2636];
YMSRE_Spatial_WOFAE     = [.3151       .2689      .2551           0.2524];
YMSRE_Spatial_WithFAE   = [.0933       .0648      0.0663          0.0640];

figure(1);
[AX, p1, p2] = plotyy(X, YSKL_Temporal_WOFAE, X, YMSRE_Temporal_WOFAE);
set(AX,'XTick', X);   % This fixes X-axis tick mark (same as data axis)

set(get(AX(1),'Ylabel'),'String','SKL Score') 
set(get(AX(2),'Ylabel'),'String','Norm. Residuals') 
xlabel('Time (\musec)') 
title('SKL and Norm. Residual plotted on different y-axes') 
set(p1,'LineStyle','--')
set(p2,'LineStyle',':')

axes(AX(1))
hold on
plot(X, YSKL_Spatial_WOFAE);
hold on
plot(X, YSKL_Spatial_WithFAE);
ylim([0 4])
hold off

axes(AX(2))
hold on
plot(X, YMSRE_Spatial_WOFAE);
hold on
plot(X, YMSRE_Spatial_WithFAE);
ylim([0.0 0.4])
hold off

剧情如下:

请注意右侧 y 轴上的刻度

问候, 杜夏特

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    在调用plotyy 之后,第二个(右侧)y 轴刻度标签被“冻结”。在 AX(2) 上调整 ylim 时,这对标签没有影响。
    因此,axes appearance 必须重置为auto。
    将以下代码与问题中的示例一起使用:

    axes(AX(2))
    hold on
    plot(X, YMSRE_Spatial_WOFAE);
    hold on
    plot(X, YMSRE_Spatial_WithFAE);
    ylim([0.0 0.4])
    % include the following statement to allow 
    % the second y-axis to reset the ticks:
    set(AX(2), 'YTickMode', 'auto', 'YTickLabelMode', 'auto')
    hold off
    

    将产生这个情节:

    【讨论】:

    • 非常感谢您帮助我。另外,对于延迟接受您的回答,请接受我的歉意。我正在度假,无法访问互联网。
    猜你喜欢
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 2020-07-13
    • 2019-07-05
    • 1970-01-01
    相关资源
    最近更新 更多