## plot and linewidth

### John (view profile)

on 22 Sep 2011
Latest activity Edited by Hari Desanur

on 15 Nov 2016

### Fangjun Jiang (view profile)

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? Thanks.

on 8 Mar 2016

Try writing like this plot(x1,y1,'Linewidth',6,x2,y2,'Linewidth',8)

Ramesh M

on 28 Jul 2016

it works thnx

### Fangjun Jiang (view profile)

on 22 Sep 2011

Probably no direct solution as you wanted. You could do:

```h=plot(x1,y1,x2,y2,'LineWidth',8);
set(h(1),'linewidth',5);
set(h(2),'linewidth',10);
```

Tyler Tomlinson

### Tyler Tomlinson (view profile)

on 2 Dec 2015

Thank you that worked great.

Mike Garrity

### Mike Garrity (view profile)

on 8 Mar 2016

Just FYI, there is an "official" syntax for setting a property to different values on different objects. However, it's really ugly, and doesn't work everywhere. For example, I don't think that the plot function accepts this form.

It looks like this:

```h = plot(x1,y1,x2,y2);
set(h,{'LineWidth'},{5;10})
```

The property name and property value need to each be a cell array, and the shape of the value cell array has to match the shape of the handle cell array.

That said, you're really better off with 2 calls to set in this case.

### Wayne King (view profile)

on 22 Sep 2011

Hi: You can use handles.

```    h = plot(x1,y1,x2,y2);
set(h(1),'linewidth',1);
set(h(2),'linewidth',2);```

### Hari Desanur (view profile)

on 15 Nov 2016
Edited by Hari Desanur

### Hari Desanur (view profile)

on 15 Nov 2016

The line width for a particular line can be set using line object handles. For example -

```   l = plot(x1,y1,x2,y2);
l(1).LineWidth = 3; % set line width of 3 for the first line (x1,y1)
l(2).LineWidth = 6;```