Programmatically change stackedplot ticks in live editor

조회 수: 3 (최근 30일)
Lima Kilo
Lima Kilo 2021년 10월 5일
답변: Ashutosh Singh Baghel 2021년 11월 18일
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
Paul Kaufmann
Paul Kaufmann 2021년 10월 5일
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 2021년 10월 5일
@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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ashutosh Singh Baghel
Ashutosh Singh Baghel 2021년 11월 18일
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.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by