필터 지우기
필터 지우기

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

조회 수: 6 (최근 30일)
Safiya
Safiya 2015년 12월 24일
댓글: Walter Roberson 2015년 12월 28일
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