How do I plot lines with different line widths?

Leor Greenberger · May 26, 2023 · 2.8K views
Question
Hi, I want to do:   plot(x1,y1,x2,y2,'LineWidth',8) but the linewidth propery ends up applying to both lines. Do I have to use two plot functions with a hold on command to have line1 a different width than line2?
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 16, 2026

Yes, you will need to use two separate plot functions with the hold on command to set different line widths for each line in MATLAB. Here's an example of how you can do this:

 
plot(x1, y1, 'LineWidth', 2); % Set the line width for the first line
hold on;                      % Hold the current plot
plot(x2, y2, 'LineWidth', 8); % Set the line width for the second line
hold off;                     % Release the plot hold

This way, each plot command will apply the specified line width to the respective line. The hold on command ensures that both lines are plotted on the same graph.

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!