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

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Arnab Sen
Arnab Sen il 28 Dic 2015
Modificato: Walter Roberson il 28 Dic 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:

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by