2nd plot on axes with different x-axis not working
Show older comments
Hi, Im trying to add 2nd plot to an axes using what I've found online. I understand it needs to be axes and not uiaxes.
So I create my first plot from a pushbutton callback
figure
ax=axes;
app.myfigaxes=ax; % assign to app property so I can recall later
plot(ax,X,Y,'LineWidth',2,'Marker','.','MarkerSize',14); grid on;
drawnow;
I have an app property called "myfigaxes"
Now behind a second pushbutton callback I want to add the 2nd plot (but it has different x-axis)
%Create 2nd "Transparent Axes"
ax=app.myfigaxes;
hax2=axes('Position',ax.Position, 'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','r','YColor','r')
hold(ax,"on"); % ax.NextPlot='add';
plot(hax2,X2,Y2,'r-','Marker','.','MarkerSize',14);
xlabel(hax2,'Second X-axis');
linkaxes([ax,hax2],'y');
But my 2nd plot is over the top of the 1st and not transparent, and the XAxislocation is at the bottom not the top as i have required.
where have I gone wrong? (the blue arrow points to a datapoint just about visible from the 1st plot)

Accepted Answer
More Answers (0)
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!