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

6 次查看(过去 30 天)
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

回答(1 个)

Arnab Sen
Arnab Sen 2015-12-28
编辑:Walter Roberson 2015-12-28
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:

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by