Azzera filtri
Azzera filtri

Rotate the plot at 45 degree

37 visualizzazioni (ultimi 30 giorni)
Sharah
Sharah il 29 Set 2016
Commentato: Raj il 11 Ago 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 Commento
Raj
Raj il 11 Ago 2023
creat a vector nameed v2 containing the last coloum of data

Accedi per commentare.

Risposte (2)

Jakub Rysanek
Jakub Rysanek il 4 Ott 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 il 29 Set 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 Commento
Ryan Webb
Ryan Webb il 1 Set 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.

Accedi per commentare.

Categorie

Scopri di più su 3-D Scene Control in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by