Programmatically change stackedplot ticks in live editor

4 views (last 30 days)
I have a stackedplot in a live script where I want to scale up the x axis labels - the values are e.g. 0.01, which i would like to read 10 without changing the data or having to adjust existing limits.
In a regular plot, that works by just editing the XTickLabels. For the stackedplot, a trick is needed to access the axis properties as described here: https://de.mathworks.com/matlabcentral/answers/486898-change-yticks-using-a-stacked-plot#answer_550223
In a normal script, the following code works fine, but in a live script, the plot does not change even though the axis property has changed as the output of the last line confirms.
x = [0 0.01 0.02 0.03];
y1 = [1 2 3 4]';
y2 = [4 3 2 1]';
s = stackedplot(x, [y1 y2]);
xlim([0 0.02]);
axs = findobj(s.NodeChildren, 'Type', 'Axes');
axs(1).XTickLabel = num2str(axs(1).XTick'*1000);
axs(1).XTickLabel
ans = 11×2 char array
' 0' ' 2' ' 4' ' 6' ' 8' '10' '12' '14' '16' '18' '20'
How do I get the live script plot to change?
  2 Comments
Paul Kaufmann
Paul Kaufmann on 5 Oct 2021
What is wrong with just scaling the x-axis within stackedplot?
s = stackedplot(x * 1000, [y1 y2]);
This doesn't change the data and does what you want. Or am I missing something?
Lima Kilo
Lima Kilo on 5 Oct 2021
@Paul Kaufmann scaling the values in the input to the plot requires changing the axis limits. I already have a number of plots with these x-axis values and I would like a "drop-in" solution to scale the axes without changing all the limits. I'll add that in the question.

Sign in to comment.

Answers (1)

Ashutosh Singh Baghel
Ashutosh Singh Baghel on 18 Nov 2021
Hi Lima,
I understand you wish to have custom XtickLabel in the live script's 'stackedplot' function call. The issue is due to the cause that ' stackedplot ' is not updating the 'XtickLabel' as it should do, although our development team is aware of the issue and investigating.
Refer to the 'stackedplot' MATLAB Documentation page for more information.

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!