Plot a vector with a given angle against the y-axis
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi, so as the title states I want to simply plot a line that will make an angle I already know with the y axis, as this line will be plotted in the same figure as other graphs I want it to also be scaled such that it can be seen in these figures as the order of magnitude changes. I know that the vector will have the slope k = sin(angle)/cos(angle) (as it will always intercept the origin) but how do I plot it so that its range is covered by the whole figure. I have attached a figure that shows an example of what I'm trying to plot ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1674306/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1674306/image.png)
댓글 수: 0
답변 (2개)
Paul
2024년 4월 20일
편집: Paul
2024년 4월 20일
Something like this? Note that the line won't won't resize if the axes are resized. If you want something like that, you might be able to use a combination of xline and hgtransform, but I didn't try it.
rng(100);
figure;scatter(randn(100,1),randn(100,1))
theta = 30;
yl = ylim;
line([yl(1)*tand(30) yl(2)*tand(30)],[yl(1) yl(2)])
댓글 수: 0
Star Strider
2024년 4월 20일
편집: Star Strider
2024년 4월 20일
Another approach —
thetad = 280; % Desired Angle (Guessing Value)
x = randn(100,1)*2;
y = randn(100,1);
% thetad = 360*rand
arcang = linspace(mod(thetad, 180), 90, 25);
arc = @(yv) [(max(yv)/2)*cosd(arcang); (max(yv)/2)*sind(arcang)];
figure
scatter(x, y, 'x')
hold on
plot(xlim*cosd(thetad), xlim*sind(thetad), '-b', 'LineWidth',2)
arcs = arc(ylim);
plot(arcs(1,:), arcs(2,:), '-b', 'LineWidth',2)
hold off
axis('equal')
title('Normal Ticks, Tick Labels, & Axes, With Solid Lines For Axes')
Ax = gca;
Ax.XAxisLocation = 'origin';
Ax.YAxisLocation = 'origin';
text(median(arcs(1,:)), median(arcs(2,:)), '\theta', 'Horiz','center', 'Vert','bottom', 'Color','b', 'FontSize',16)%, 'FontWeight','bold')
% get(Ax)
figure
scatter(x, y, 'x')
hold on
plot(xlim*cosd(thetad), xlim*sind(thetad), '-b', 'LineWidth',2)
arcs = arc(ylim);
plot(arcs(1,:), arcs(2,:), '-b', 'LineWidth',2)
hold off
axis('equal')
xline(0, '--k', 'LineWidth',2) % Draw Y-Axis
yline(0, '--k', 'LineWidth',2) % Draw X-Axis
title('Invisible Itcks, Tick Labels, & Axes, With Dashed Lines For Axes')
Ax = gca;
Ax.XAxis.Visible = 0;
Ax.YAxis.Visible = 0;
text(median(arcs(1,:)), median(arcs(2,:)), '\theta', 'Horiz','center', 'Vert','bottom', 'Color','b', 'FontSize',16)%, 'FontWeight','bold')
EDIT — (20 Apr 2024 at 19:14)
Made ‘arcang’ more robust.
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!