multiple plots in one figure with left and rigt y-axis with different units

1 vue (au cours des 30 derniers jours)
Safiya
Safiya le 24 Déc 2015
Commenté : Walter Roberson le 28 Déc 2015
Hi , I have 5 data sets. i would like to plot data1 to data3 (voltage V) on left y-scale and data4, 5 (current mA) on right y-axis.
data1 to data3 : min = 0 max=4.7V
data 4 , 5 : min =100mA , max 800mA
thanks

Réponses (1)

Arnab Sen
Arnab Sen le 28 Déc 2015
Modifié(e) : Walter Roberson le 28 Déc 2015
It is my understanding that you would like to plot for both left and right Y-axis for different datasets. For this purpose, you can create multiple axes using 'axes' function and plot the datasets referring the appropriate axes as the argument.
The following example will illustrate how to achieve the above
%Construct the left Y-axes
>> ax1=axes('XAxisLocation','bottom',...
'YAxisLocation','left',...
'Color','none',...
'XColor','k',...
'YColor','r',...
'YLim',[0 4.7],'NextPlot','add');
% Construct the right Y-axis
>> ax2=axes('XAxisLocation','bottom',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k',...
'YColor','r',...
'YLim',[100 800],'NextPlot','add');
% Put the labels of all the axes
>> xlabel(ax1,'Xlabel')
>> ylabel(ax1,'Voltage(V)')
>> ylabel(ax2,'Current(ma)')
% Plot the datasets in appropriate axes
>> plot(ax1,x,data1,'color',rand(1,3));
>> plot(ax1,x,data2,'color',rand(1,3));
>> plot(ax1,x,data3,'color',rand(1,3));
>> plot(ax2,x,data4,'color',rand(1,3));
>> plot(ax2,x,data5,'color',rand(1,3));
if you have only two datasets one for each left and right Y axis, you can simply use 'plotyy' function instead.
You may use various properties of the lines by by setting appropriate arguments in 'plot' function call.
Refer to the following link for more detail of 'plot', 'axes' and 'plotyy' functions:

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by