Rotate the plot at 45 degree

71 Ansichten (letzte 30 Tage)
Sharah
Sharah am 29 Sep. 2016
Kommentiert: Raj am 11 Aug. 2023
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 Kommentar
Raj
Raj am 11 Aug. 2023
creat a vector nameed v2 containing the last coloum of data

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jakub Rysanek
Jakub Rysanek am 4 Okt. 2016
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 am 29 Sep. 2016
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 Kommentar
Ryan Webb
Ryan Webb am 1 Sep. 2022
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 3-D Scene Control finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by