How to change x-axis without changing datapoints?

18 ビュー (過去 30 日間)
Dominik Coenen
Dominik Coenen 2023 年 9 月 7 日
移動済み: dpb 2023 年 9 月 7 日
Hi there,
I am trying to change the labels of XAxis and YAxis. The labels need to start at 0,0 without changing the data points and keep the correct scale. What is the best way to do this?
I tried to change the xticklabels and yticklabels but then the distance between two data points was not the same as on the x-axis.
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 7 日
What should be the values for the tick labels instead of the current values?

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2023 年 9 月 7 日
Here are two ways of changing the plot —
x = linspace(536000, 543000, 500).';
yax = linspace(532900, 533400, 500).';
B = [x(:) ones(500,1)] \ yax(:);
y = [1E+3*sin(2*pi*x*3/(max(x)-min(x))) ones(500,1)] * B;
figure
plot(x, y)
title('Original')
xt = xticks;
yt = yticks;
figure
plot(x, y)
xticklabels(xt - xt(1))
yticklabels(yt - yt(1))
title('Changed Tick Labels')
xnew = x - min(x);
ynew = y - min(y);
figure
plot(xnew, ynew)
title('Shifted Function')
.

その他の回答 (1 件)

dpb
dpb 2023 年 9 月 7 日
移動済み: dpb 2023 年 9 月 7 日
One could meet the request as stated with
xl=xlim; xticklables=xticks-xl(1);
yl=ylim; yticklables=yticks-yl(1);
What other unstated expectations @Dominik Coenen has may or may not be possible to be met...

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by