Plot with Multiple x-Axes and y-Axes using the fill function
5 次查看(过去 30 天)
显示 更早的评论
Following this example:
I understand how to plot with multiple axes. But when I add the fill function to display a confidence interval to each line the second fill function messes up the axes properties. My code is:
figure
x1 = 0:0.1:40;
y1 = 4.*cos(x1)./(x1+2);
fill([x1 fliplr(x1)],[y1+0.1 fliplr(y1-0.1)],'b')
alpha(0.2)
line(x1,y1,'Color','k')
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
x2 = 1:0.2:20;
y2 = x2.^2./x2.^3;
fill([x2 fliplr(x2)],[y2+0.1 fliplr(y2-0.1)],'r','Parent',ax2)
alpha(0.2)
line(x2,y2,'Parent',ax2,'Color','k')
If I comment out the second fill function it works nicely upon getting annoying tickmarks on ax2 from ax1. Where is my problem? Thanks in advance!
/Markus
0 个评论
采纳的回答
A. Sawas
2019-4-8
It seems Matlab is resetting ax2 settings to default after the fill command.
add this line after the fill command to set them again.
set(ax2,'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!