MATLAB: How to add a dashed horizontal line at 0 using plot function #plot #horizontallinehorizontal lineMATLAByline How I do add a dashed horizontal line on a graph using the plot function? Best Answer 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=5plot([0,5],[0,0], 'k--')% Plot a line at y=0 that spans the current x-limits of your axesplot([min(xlim()),max(xlim())],[0,0], 'k--') Related SolutionsMATLAB: Add lines along the axes I am not certain what you want.Try this:x = linspace(-2, 5, 250);y = sin(2*pi*x + 0.2) + 0.3;figureplot(x, y)hold onplot([0 0], ylim, '--') % Dashed Vertical Line at x=0plot(xlim, [0 0], '--') % Dashed Horizontal Line at y=0hold offgrid MATLAB: Voronoi Diagram in Dashed Lines Try to grab only handles of voronoi linesset(h(2:end),'linestyle','--') Related QuestionChange the Yaxis to dashed lineHow to draw a vertical line with a given heightDashed confidence intervals and xlabelHow to draw lines in matlab figure
Best Answer