Matlab:在同一图形中使用绘图和符号(Matlab 2014)

Matlab:在同一图形中使用绘图和符号(Matlab 2014),matlab,plot,graph,Matlab,Plot,Graph,我想在同一个图中使用plot和semilog来比较结果。通过使用保持功能,我只得到一个波形。我能做什么?我不能使用yyaxis left,因为我的matlab低于2016。有什么帮助吗 这是我的密码: figure semilogy(VG, ID3) hold on plot(VG, ID3) hold off 我经常需要在线性空间和对数空间中比较数据。使用子地块堆叠绘图提供了良好的视觉效果。例如: % set up dummy data that is evenly-space in log

我想在同一个图中使用plot和semilog来比较结果。通过使用保持功能,我只得到一个波形。我能做什么?我不能使用yyaxis left,因为我的matlab低于2016。有什么帮助吗

这是我的密码:

figure
semilogy(VG, ID3)
hold on
plot(VG, ID3)
hold off

我经常需要在线性空间和对数空间中比较数据。使用子地块堆叠绘图提供了良好的视觉效果。例如:

% set up dummy data that is evenly-space in logspace
x = 10.^((linspace(log10(.01), log10(10),20))');
y = rand(20, 1);
% finish setup

figure

subplot(2,1,1)
plot(x, y, 'DisplayName', 'MyData')
title('Plot with Linear Axes')
xlabel('X-Axis')
ylabel('Y-Axis')
grid on
set(legend, 'Location', 'best')

subplot(2,1,2)
semilogx(x, y, 'DisplayName', 'MyData')
title('Plot with LogX Axis')
xlabel('LogX-Axis')
ylabel('Y-Axis')
grid on
set(legend, 'Location', 'best')
上述情况产生了以下结果:
将线性图和半对数图放在同一个图中的可能解决方案是创建两个重叠的图:

首先,可以使用线性比例绘制数据 在第二种情况下,您可以使用对数刻度在x轴或轴上绘制数据 主要步骤是:

塑造形象 在图形中创建第一个轴 将轴的颜色设置为与数据相同的颜色,这将有助于识别数据 用plot绘制数据 在图形中创建第二个轴,并将其大小设置为第一个轴之一,此时secon轴处于活动状态 将X轴位置移动到图表顶部 将Yaxis位置移到图表的右侧 用符号学绘制数据 将轴的颜色设置为与数据相同的颜色,这将有助于识别数据 添加标题、图例和x/y标签 因为我们已经改变了第二个轴的X轴和Y轴的位置,所以我们需要调整图形和轴的尺寸,以便它们能够配合在一起

现在,您可以修复两个轴的不同栅格的问题:

为此,可以使用uimenu功能将菜单项添加到菜单栏,以切换网格

在下文中,介绍了建议方法的可能实施

由于您尚未指定是否使用R2014a或R014b,因此在下面的代码中,您可以找到设置地物和轴特性的方法:

旧方法:使用get/set R2014b提供了新的单点表示法 最后一个是评论

% Define input data
x=linspace(0,30,30)
y=rand(30, 1);

% Cretate a Figure
f=figure('units','normalized')

% Create the first axes in the figure
ax1=axes
% Plot the data with "PLOT"
ph=plot(x,y,'r')
% Set the axis labeks
xlabel('X data')
ylabel('Y data, LIN mode')
% Get the position of the first axes
% % % % % % % % % % % % % % % % % % % % % % % % ax1_pos=ax1.Position
ax1_pos=get(ax1,'position')
% Set the color of the fist axes
% % % % % % % % % % % % % % % % % % % % % % % % ax1.XColor='r'
% % % % % % % % % % % % % % % % % % % % % % % % ax1.YColor='r'
set(ax1,'xcolor','r','ycolor','r')

% Add the second axes in the figure
ax2=axes('position',ax1_pos)
% Plot the data with SEMILOGY
slh=semilogy(x,y,'b')
% Set the ylabel
ylabel('Y data, LOG mode')
% Set the title of the chrt
title('Linear and Semilog Plot')

% Move the X axis location to the top of the chart
% % % % % % % % % % % % % % % % % % % % % % % % ax2.XAxisLocation='top'
set(ax2,'XAxisLocation','top')
% Move the XYaxis location to the right of the chart
% % % % % % % % % % % % % % % % % % % % % % % % ax2.YAxisLocation='right'
set(ax2,'YAxisLocation','right')
% Set the color of the second axes to transparent
% % % % % % % % % % % % % % % % % % % % % % % % % ax2.Color='none'
set(ax2,'color','none')
% Set the color of the second axes
% % % % % % % % % % % % % % % % % % % % % % % % % ax2.XColor='b'
% % % % % % % % % % % % % % % % % % % % % % % % % ax2.YColor='b'
set(ax2,'xcolor','b','ycolor','b')
% Add the lgend to the chart
legend([ph slh],'plot','semilogy','location','best')

% Adjust the size of the the first axes
% % % % % % % % % % % % % % % % % % % % % % % % ax1.Position=[ax1_pos(1) ax1_pos(2) ax1_pos(3)*.9 ax1_pos(4)*.9]
set(ax1,'position',[ax1_pos(1) ax1_pos(2) ax1_pos(3)*.9 ax1_pos(4)*.9])
% et the size of the second axes as per the first one
ax2.Position=ax1.Position
set(ax2,'position',[ax1_pos(1) ax1_pos(2) ax1_pos(3)*.9 ax1_pos(4)*.9])

% Adjust the size of the figure
% % % % % % % % % % % % % % % % % % % % % % % % % % % fp=f.Position
fp=get(f,'position')
% % % % % % % % % % % % % % % % % % % % % % % % % % % f.Position=[0.1,0.1,fp(3)*1.2,fp(4)*1.2]
set(f,'position',[0.1,0.1,fp(3)*1.2,fp(4)*1.2])

% Add the menu to manage the grid
mh=uimenu('Label','Grid manag.')
m1h=uimenu(mh,'Label','Linear Grid','callback', ...
   'axes(ax1);grid;axes(ax2);if(strcmp(m1h.Checked,''off'')),m1h.Checked=''on'';else,m1h.Checked=''off'';end')
m2h=uimenu(mh,'Label','Log Grid','callback', ...
   'axes(ax2);grid;if(strcmp(m2h.Checked,''off'')),m2h.Checked=''on'';else,m2h.Checked=''off'';end')

是否要在线性轴和对数轴上绘制相同的数据?你可能想用两个独立的轴来做这件事,否则你会把每个人都搞糊涂的。我很矛盾。这是一个写得很好的完整答案。但是它帮助人们做一些非常糟糕的事情…: