Plot with Multiple x-Axes and y-Axes using the fill function
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
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 Kommentare
Akzeptierte Antwort
  A. Sawas
      
 am 8 Apr. 2019
        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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

