How to add vertical line in z direction in YZ view meshplot?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it's too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I'm trying to achive in code:
0 comentarios
Respuestas (2)
akshatsood
el 10 de Dic. de 2023
Editada: akshatsood
el 10 de Dic. de 2023
I understand that you are seeking guidance to add a vertical line in the Z direction within the YZ view of the mesh plot. Although you have attempted line annotation, it did not seem to be a feasible solution.
To address this issue, you can utilize the "line" function to plot a vertical line at the position y=0. In the following approach, I have plotted a line while keeping the X value fixed at its maximum, ensuring it appears in front of the mesh plot. Additionally, I extended a vertical line starting from [0, 0] to [min(Z(:)), max(Z(:))]. This method fulfills the requirements mentioned in the question. Here is the code snippet for your reference
% assuming random data
[X, Y, Z] = peaks(100);
subplot(1,2,1);
mesh(X, Y, Z);
subplot(1,2,2);
mesh(X, Y, Z)
view(90,0); % YZ view
hold on;
% add vertical line centered on Y-axis
line([max(X(:)) max(X(:))], [0 0], [min(Z(:)) max(Z(:))], ...
'Color', 'r', 'LineWidth', 2, 'LineStyle', '--');
hold off;
title('YZ View');
I hope this helps.
2 comentarios
Dyuman Joshi
el 10 de Dic. de 2023
You can directly use the variables -
% assuming random data
[X, Y, Z] = peaks(100);
mesh(X, Y, Z)
view(90,0); % YZ view
hold on;
xLimits = xlim;
zLimits = zlim;
% add vertical line centered on Y-axis
line(xLimits, [0 0], zLimits, ...
'Color', 'r', 'LineWidth', 2, 'LineStyle', '--');
hold off;
title('YZ View');
Star Strider
el 10 de Dic. de 2023
I do not completely understand how you are creating the ‘YZ’ view.
If you are creating it using ‘vlew(90,0)’ the first option works, if you are creating it using ‘view(-90,0)’ the second option works. Both should automatically adapt to whatever the axil limits are.
Try these —
[X,Y,Z] = peaks(50);
figure
mesh(X, Y, Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
hold on
plot3([0 0]+max(xlim), [0 0], zlim, '--k', 'LineWidth',3)
plot3([0 0]+min(xlim), [0 0], zlim, '--k', 'LineWidth',3)
hold off
figure
mesh(X, Y, Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
hold on
plot3([0 0]+max(xlim), [0 0], zlim, '--k', 'LineWidth',3)
hold off
view(90,0)
figure
mesh(X, Y, Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
hold on
plot3([0 0]+min(xlim), [0 0], zlim, '--k', 'LineWidth',3)
hold off
view(-90,0)
.
2 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!