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 CenterFile Exchange에서 3-D Scene Control에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by