How to add a dashed horizontal line at 0 using plot function?
    98 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Anne Nguyen
 el 29 de Sept. de 2019
  
    
    
    
    
    Comentada: shahriar sowad
 el 1 de Jul. de 2021
            How I do add a dashed horizontal line on a graph using the plot function?
0 comentarios
Respuesta aceptada
  Adam Danz
    
      
 el 29 de Sept. de 2019
        
      Editada: Adam Danz
    
      
 el 2 de Oct. de 2019
  
      Here are 3 options to add a dashed horizontal line to a plot. The 1st option is recommended if you're using matlab r2018b or later. 
% Use yline() to plot a horizontal line at y=0 (requires r2018b or later)
% https://www.mathworks.com/help/matlab/ref/yline.html
% This will automatically adjust if your xlim changes.
yline(0,'k--')
% Plot a line at y=0 that spans from x=0 to x=5
plot([0,5],[0,0], 'k--')
% Plot a line at y=0 that spans the current x-limits of your axes
plot([min(xlim()),max(xlim())],[0,0], 'k--')
3 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Discrete Data Plots en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


