Current axis tick vector differ between having figure visible and invisible
32 views (last 30 days)
Show older comments
I am creating a plot that can be summarized as
fig = figure('visible', 'off');hold on;
plot(y_data);
colororder({'k'}); % Force right y-axis to be black
yyaxis('right'); hold on;
plot(yy_data);
When I get current axes and check the YTicks after plotting in the right axis, the ax.YTick vector matches what is on the right axis. However, if I switch back to the left axis, I get a shorter vector of YTicks than is on the left axis (only first, middle and last). This is also the case when I query the current axes right after plotting on the left axis. But if I make the figure visible and then query the YTicks on the left axis, the values in the array matches exactly what is in the left axis of the plot.
What am I missing? There must be another explanation than whether the figure is visible, I'm sure.
5 Comments
dpb
about 1 hour ago
Edited: dpb
about 1 hour ago
As noted, seems peculiar, but at least so far I've not been able to reproduce it. Mayhaps is buried in the bowels of what is different in the systems rendering code and/or firmware/hardware.
On your comment "colororder({'k'}) because I do not want my axis to have the same color as the first line I draw in this axis", you can set the YAxis.Color property to whatever you wish it to be. It's OK to reset the color order if you want; I was just curious as to why it was in the code in the particular instance.
%hAx=axes;
yyaxis('left')
yyaxis('right')
figure
%axes
yyaxis('left')
yyaxis('right')
hAx=gca;
hAx.YAxis(2).Color='k';
The second has the RH y axes color as black without changing the default color order; you can, then plot into either left/right with whatever color assignments you want for each line or continue on with the default color order. You'll note the above two figures both have the default blue LH color.
If you set 'box','on' it will be whichever is the axes in focus.
Regarding hold on it resets the auto-ranging to 'on'; wasn't sure but what your app might have formerly reset autoscaling off and that was what was turning it back on and thus changing ticks/marks, not having the entire session.
Answers (1)
Walter Roberson
about 14 hours ago
Automatic ticks are not reliably computed until you make the figure visible again.
As long as the figure is invisible, the plot is treated as-if the size of the plotting area is unknown -- and the size of the plotting area is one factor in determining the automatic tick marks.
See Also
Categories
Find more on Axis Labels 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!
