MATLAB Answers

How to change the origin from (0,0) to different coordinates in a plot

282 ビュー (過去 30 日間)
FD
FD 2019 年 4 月 18 日
回答済み: Kelly Kearney 2019 年 4 月 18 日
I have two datasets with 1100x1 double. The rows represent different time points, while the values within each cell of the dataset represent a certain width. Therefore, there are 1100 time points. Matlab treats these data as starting from time zero. However, recording started from time -100.
When I plot these data on the same figure (with Matlab 2018a)
plot(x,'-b');
hold on
plot(y, '-r');
the x and y axis are automatically placed on the bottom (the x axis) and left (y axis) of the plot. I would like to move the axes to time point 0 and width 0.
I can move the x axis with:
ax.XAxisLocation = 'origin';
However, I cannot do the same for the y axis, as Matlab uses as 'origin' for the y axis the default (0,0), rather than the (100,0).
I know that I could simply draw a new line to create the new y axis with
plot([100 100], ylim, 'k-', 'LineWidth',1);
but I want to keep ticks and tick labels as they are in the default settings.
How can I move the y axis? Is thre a way to do something like this: ax = gca; ax.YAxisLocation = (ax.XLim(1)+100); %which doesn't working

  0 件のコメント

サインイン to comment.

回答 (2 件)

Hassan Nawaz
Hassan Nawaz 2019 年 4 月 18 日
Hi, You can try using the axis command. With this you can adjust as per your desire how the overall posittive and negative range will look like. the syntax is as
axis([-x +x -y +y])

  1 件のコメント

FD
FD 2019 年 4 月 18 日
So, in my example, which values should I be using?

サインイン to comment.


Kelly Kearney
Kelly Kearney 2019 年 4 月 18 日
You don't need to move the axis; you need to provide x-values for your data.
Right now, you're using the ydata-only option for plot. When you do that, it assumes that the x values are 1:length(y). So
plot(x,'-b');
is the equivalent of
plot(1:length(x), x, '-b');
Instead, provide the real x values. In your case, that's probably something like:
t0 = -100;
dt = 0.01; % or whatever the spacing is in your points.
t = t0 + (0:length(x)-1).*dt;
plot(t, x, '-b')

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2018a

Translated by