PLOTYY : 2-D line plots with y-axes on both left and right side


This section explains how to plot more than two graphs on two y-axes using plotyy function in MATLAB.id_vgs

  • plotyy(X1,Y1,X2,Y2) plots X1 versus Y1 with y-axis labeling on the left(y1-axis) and plots X2 versus Y2 with y-axis labeling on the right.
  • plotyy(X1,Y1,X2,Y2,’function’) uses the plotting function specified by the string ‘function’ to produce the graphs. ‘function’ can be plot, semilogx, semilogy, loglog, stem or any MATLAB function that accepts the syntax: h = function(x,y)
  • plotyy(X1,Y1,X2,Y2,’function1′,’function2′) uses function1(X1,Y1) to plot the data for the left axis and function1(X2,Y2) to plot the data for the right axis.
  • [AX,H1,H2] = plotyy(…) returns the handles of the two axes created in AX and the handles of the graphics objects from each plot in H1 and H2. AX(1) is the left axes and AX(2) is the right axes out of which only one axis is active at a time.
  • In the following example the plotyy function is used to plot the drain current in linear scale on left side and in log scale on  right side. The scale version of current(0.9*id_mA) is plotted on the left y-axis.
  • Legend for plotyy with multiple figures :
    Create legend on the same box for both axes
    legend([H1;H2],’I_{D1}’,’I_{D2}’,’I_{D1}’);
    Create legend on different legend boxes for the two axes
    legend(AX(1),’I_{D1}’,’I_{D2}’,’Location’,’NorthWest’);
    legend(AX(2),’I_{D1}(log)’,’Location’,’SouthEast’);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
clear all; clc;
% Load data into variables from file
nmos1=load('nmos.csv');
id = nmos1(:,2);
id_mA = id*1000;
vgs= nmos1(:,1);
 
% plot data using plotyy
[AX H1 H2]=plotyy(vgs,[id_mA id_mA*0.9],vgs,id,'plot','semilogy');
grid on;
 
% Create ticks for y-axes
idmin=floor(min(id_mA));
idmax=ceil(max(id_mA));
delta_id=(idmax-idmin)/10;
set(AX(1),'YTick',[idmin:delta_id:idmax]);
set(AX(2),'YTick',logspace(-9,0,10));
 
%
legend(AX(1),'I_{D1}','I_{D2}','Location','NorthWest');
legend(AX(2),'I_{D1}(log)','Location','SouthEast');
% Label the axes
xlabel('V_{gs}(V)');
set(get(AX(1),'Ylabel'),'String', 'Drain current (mA)');
set(get(AX(2),'Ylabel'),'String', 'Drain current (mA) -- log scale');
% Save the plot
print -dpng -r100 id_vgs.png;

Leave a Comment