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 Center および File ExchangeSurface 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