Matlab plotyy painting double ordinate diagram example

Source: Internet
Author: User

Matlab plotyy painting double ordinate diagram example

x = 0:0.01:20;
Y1 = 200*exp ( -0.05*x). *sin (x);
y2 = 0.8*exp ( -0.5*x). *sin (10*x);
[AX,H1,H2] = Plotyy (x,y1,x,y2, ' plot ');

Set (AX (1), ' Xcolor ', ' k ', ' Ycolor ', ' B ');
Set (AX (2), ' Xcolor ', ' k ', ' Ycolor ', ' R ');

Hh1=get (AX (1), ' Ylabel ');
Set (HH1, ' String ', ' left Y-axis ');
Set (HH1, ' Color ', ' B ');

Hh2=get (AX (2), ' Ylabel ');
Set (HH2, ' String ', ' right Y-axis ');
Set (HH2, ' Color ', ' r ');

Set (H1, ' LineStyle ', '-');
Set (H1, ' Color ', ' B ');
Set (H2, ' LineStyle ', ': ');
Set (H2, ' Color ', ' r ');

Legend ([h1,h2],{' y1 = 200*exp ( -0.05*x). *sin (x) '; ' y2 = 0.8*exp ( -0.5*x). *sin (10*x) '});
Xlabel (' Zero to musec. ');
Title (' Labeling Plotyy ');

Q: Can I get rid of the tick with blue circle on the right? Due to the use of plotyy drawing, in order to make the diagram appear as far as possible, with Set (AX (1), ' Ylimmode ', ' auto '), but this may cause the left AX (1) and the right ax (2) The tick spacing is not the same, the effect is beautiful. Or can you make plotyy draw the same tick spacing on both sides of the graph so that the tick on the right side of the graph will overlap.

A: If you just want to make plotyy a little more beautiful, you can use the following form of invocation:
[AX,H1,H2] = Plotyy (...)
where AX (2) is the handle to the right axes object, it can be set or get to deal with it, or it can be ytick off.

A: You can also use the line statement to draw, there is no left and top lines.

Q:plotyy (x1,y1,x2,y2,fun1,fun2), how should FUN1 and FUN2 be written?

A: These two fun plotyy do not necessarily have to use two plots, such as the following example, a curve with plot, a semilogy

x1=1:0.1:100;
x2=x1;
y1=x1;
y2=x2.^3;
Plotyy (X1,y1,x2,y2, @plot, @semilogy)

Source: http://hi.baidu.com/wang_pw/blog/item/ede4c1fd6e51773d5c6008f2.html

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matlab painting double Ordinate

A graphic with two ordinate scales
In MATLAB, if you need to draw two graphs with different ordinate scales, you can use the Plotyy drawing function. The calling format is:
Plotyy (X1,y1,x2,y2)
Where x1,y1 corresponds to a curve, x2,y2 corresponds to another curve. Horizontal axis of the same scale, the ordinate has two, left ordinate for x1,y1 data pairs, right ordinate for x2,y2 data pair.

The double y-axis coordinates can be implemented with PLOTYY (X,Y1,X,Y2)
Double x coordinates can be used
Set (GCA, ' xaxislocation ', ' bottom ', ' Xticklabel ', {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 '}) (assuming the x axis is labeled as 1,2,3,4)
Set (GCA, ' xaxislocation ', ' top ', ' Xticklabel ', {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 '})
Make the appropriate settings

"* Example 10.7.3-1" to create a dual coordinate system for the performance of high and low temperature two different amounts of transition process.

tp= (0:100)/100*5;yp=8+4* (1-exp ( -0.8*TP). *cos (3*TP)); % Pressure Data

tt= (0:500)/500*40;yt=120+40* (1-exp ( -0.05*TT). *cos (TT)); % Temperature Data

% generated double coordinate system graphics

CLF reset,h_ap=axes (' Position ', [0.13,0.13,0.7,0.75]); %<4>

Set (H_ap, ' Xcolor ', ' B ', ' Ycolor ', ' B ', ' Xlim ', [0,5], ' Ylim ', [0,15]);

nx=10;ny=6; %<6>

Pxtick=0: ((5-0)/nx): 5;pytick=0: ((15-0)/ny): 15; %<7>

Set (H_ap, ' XTick ', Pxtick, ' Ytick ', Pytick, ' Xgrid ', ' on ', ' Ygrid ', ' on ')

H_linet=line (TP,YP, ' Color ', ' B '); %<9>

Set (Get (H_ap, ' Xlabel '), ' String ', ' Time/rightarrow (min) ')

Set (Get (H_ap, ' Ylabel '), ' String ', ' Pressure/rightarrow (/times10 ^{5} Pa) ')

H_at=axes (' Position ', Get (H_ap, ' Position ')); %<12>

Set (H_at, ' Color ', ' none ', ' Xcolor ', ' r ', ' Ycolor ', ' R '); %<13>

Set (H_at, ' xaxislocation ', ' top ')%<14>

Set (H_at, ' yaxislocation ', ' right ', ' Ydir ', ' rev ')%<15>

Set (Get (H_at, ' Xlabel '), ' String ', '/fontsize{15}/fontname{script} Time/rightarrow (min) ')

Set (Get (H_at, ' Ylabel '), ' String ', ' ({/circ}c)/fontsize{15}/leftarrow/fontname{script} minus temperature ')

Set (H_at, ' Ylim ', [0,210])%<18>

Line (Tt,yt, ' Color ', ' r ', ' Parent ', h_at)%<19>

Xpm=get (h_at, ' Xlim '); %<20>

TXTICK=XPM (1):((XPM (2)-xpm (1))/nx): xpm (2); %<21>

Tytick=0: ((210-0)/ny): 210; %<22>

Set (H_at, ' XTick ', Txtick, ' Ytick ', Tytick)%<23>



Source: http://hi.baidu.com/goodenoughcui/blog/item/e9a00b8b7ad52d6f9e2fb4d2.html

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Instance (verified):

CLC
Clear all;
Close all;
X=0:0.1:2*pi;
Y1=sin (x);
Y2=cos (x);
[Ax]=plotyy (X,y1,x,y2);
Set (Get (GCA, ' Xlabel '), ' string ', ' x-axis ');
Set (Get (AX (1), ' Ylabel '), ' string ', ' left Y-axis ');
Set (Get (AX (2), ' Ylabel '), ' string ', ' right Y-axis ');
Set (GCA, ' XTick ', [0:0.5:7]);
Set (AX (1), ' Ytick ', [ -1:0.2:1]);
Set (AX (2), ' Ytick ', [ -1:0.5:1]);

There is still a problem: This setting method can be set for the minimum units of each axis, but the scale range (X-0~7), y1 ( -1~1) cannot be set.
2010-12-23 Revision

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clc
Clear All
Close all
runoff=[10700 11400 15800 22900 43100 40700 50500 46000 41800 35000];
sed=[0.105 0.094 0.156 1.264

0.363 0.429 0.731 0.682 0.654 0.290];
M=1:10;
[Ax,h1,h2]=plotyy (m,runoff,m,sed); %h--Line Handle
Set (Get (Ax (1), ' Ylabel '), ' string ', ' runoff (m^3/s) ') ', ' Color ', ' r ')%y1
Set (Get (Ax (2), ' Ylabel '), ' string ', ' sediment concentration (kg/m^3) ', ' Color ', ' k ')%y2
Xlabel (' Month ')
Set (H1, ' LineStyle ', '-', ' Color ', ' r ');
Set (H2, ' LineStyle ', '--', ' color ', ' k ');
Legend ([H1 H2], ' runoff ', ' sediment concentration ')% callout two lines
Legend (' Boxoff ')
% box off
Set (Ax (:), ' Ycolor ', ' k ')% set two y-axis color to Black
Set (Ax (1), ' Ytick ', [0:10000:100000]); % set y-axis interval
Set (Ax (2), ' Ytick ', [0:0.1:1.5])
Set (ax, ' Xlim ', [1 12])% setting X-axis range
On
Scatter (Ax (1), 4,22900, ' r* ')
Axes (ax (2));
On
Scatter (4,1.264, ' ro ')

Source: http://hi.baidu.com/imhuanxi/blog/item/a1f69bcadf68a54af21fe7d2.html

April 22, 2011 Added

Matlab plotyy painting double ordinate diagram example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.