Tuesday, November 30, 2010

plotyy

plotyy - plot with two y-axes, independently control each axis

notes:
(1) specify the x-axis to be exactly the same for both
(2) define the handles for the axes and lines/objects AX(1) is left axis handle, AX(2) is right axis handle

long convoluted example:
    [AX,H1,H2] = plotyy(jda(event),sei(event), ...
        jda(event),dis(event));
    


    set(get(AX(1), 'Ylabel'), 'String', 'seismicity (m/s)', ...
        'FontName', 'Arial', 'FontSize', 12, 'FontWeight', 'bold')
    set(get(AX(2), 'Ylabel'), 'String', 'discharge (m^3/s)', ...
        'FontName', 'Arial', 'FontSize', 12, 'FontWeight', 'bold')
    set(AX(1), 'YLim', [0 .000001], ...
        'XLim', [axismat(1) axismat(4)], ...
        'XTick', axismat, ...
        'YTick', ...
        [0 .0000002 .0000004 .0000006 .0000008 .000001], ...
        'LineWidth',1.5, ...
        'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12) 
    set(AX(2), 'YLim', [0 5000], ...
        'XLim', [axismat(1) axismat(4)], ...
        'XTick', axismat, ...
        'YTick', [0 1000 2000 3000 4000 5000], 'LineWidth',1.5, ...
        'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12) 
    set(H1, 'Marker', 'o', 'LineStyle', 'none', 'MarkerSize', 3);
    set(H2, 'LineWidth', 2);
    axis ([AX(1) AX(2)], 'square');
    xlabel('julian day','FontName', 'Arial', ...
        'FontWeight', 'bold', 'FontSize', 12);

    set(gca, ...
    'LineWidth',1.5, ...
    'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12) 



2 comments: