Vertical grid line for x=0
101 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jan w
el 1 de En. de 2017
Comentada: Star Strider
el 17 de Dic. de 2020
I am using horizontal gridlines for a plot.
ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';
How can I add only one vertical line through x=0?
0 comentarios
Respuesta aceptada
Star Strider
el 1 de En. de 2017
You can plot a vertical line anywhere by duplicating the x-coordinate and plotting it against ylim:
figure(1)
plot([0 0], ylim, '-r')
ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';
0 comentarios
Más respuestas (2)
Image Analyst
el 1 de En. de 2017
The best answer is to use YAxisLocation:
theta = linspace(-pi, pi, 800);
plot(theta, sin(theta), 'b-') % Plot something.
% Make axes go through origin instead of left and bottom sides of axes box.
ax = gca;
ax.XAxisLocation = 'origin'
ax.YAxisLocation = 'origin'
4 comentarios
Image Analyst
el 2 de En. de 2017
You're welcome. Maybe you could "Vote" for the answer (under my logo).
the cyclist
el 1 de En. de 2017
Editada: the cyclist
el 1 de En. de 2017
line([0 0],[0 1],'Color','Black')
2 comentarios
Brian Russell
el 16 de Dic. de 2020
You simply need to write yline(0) or xline(0) for vertical and horizontal lines.
Star Strider
el 17 de Dic. de 2020
Note that xline and yline were introduced in R2018b, 1½ years after this was posted.
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels 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!