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

1 回表示 (過去 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:
  1 件のコメント
Walter Roberson
Walter Roberson 2015 年 12 月 28 日
There are also file exchange contributions such as plotyyy

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by