Rotate the plot at 45 degree

76 ビュー (過去 30 日間)
Sharah
Sharah 2016 年 9 月 29 日
コメント済み: Raj 2023 年 8 月 11 日
Can anyone tell me how to rotate the plot from the following image so that the now the linear reference line will be a straight vertical line, and the red and green line will fall on the left side of the plot?
for a reference the red and green line is just a data that I plot with different slope.
  1 件のコメント
Raj
Raj 2023 年 8 月 11 日
creat a vector nameed v2 containing the last coloum of data

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

回答 (2 件)

Jakub Rysanek
Jakub Rysanek 2016 年 10 月 4 日
I would simply rotate all data using the planar (2D) transform with respect to the origin:
angle = pi/4;
reference_line = [0 1 2 3 4 5 6];
data_x = [0 1 2 3 4 5 6];
data_y = [0 1.1 2.2 3.3 4.4 5.5 6.6];
% 2D rotation
x2 = data_x*cos(angle)-data_y*sin(angle);
y2 = data_y*cos(angle)+data_x*sin(angle);
figure;
hold on;
p1=plot(reference_line,reference_line,'marker','none','linestyle','--');
p2=plot(data_x,data_y,'-r');
p3=plot(x2,y2,'-b');
p4=plot(zeros(1,7),reference_line,'-k');
set(gca,'ylim',[0 6],'xlim',[-6 6]);
axis square;
legend([p1,p2,p3,p4],{'Reference line','Original data','Rotated data','Vertical line'},'Location','southwest');

Walter Roberson
Walter Roberson 2016 年 9 月 29 日
Create an hgtransform, set the axes parent to be the transform, set the rotation matrix for the transform to have the appropriate rotation.
Note: this will transform the axes too, rotating the entire plot.
If you want just the data to be rotated then the easiest single way would probably:
[th, r] = cart2pol(x, y);
[nx, ny] = pol2cart(th+pi/4, r);
Your x and y arrays will need to be the same size for this to work, so if you have multiple columns in your y array (one column per line) and a vector x, then use repmat(x(:), 1, size(y,2)) as the x for the rotation.
  1 件のコメント
Ryan Webb
Ryan Webb 2022 年 9 月 1 日
Can you clarify on "set the axes parent to be the transform"
set(ax,'Parent',t)
gives the error:
Error using matlab.graphics.axis.Axes/set
Axes cannot be a child of Transform.

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

カテゴリ

Help Center および File Exchange3-D Scene Control についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by