# Change line length in legend with Plots

**URL:** <https://discourse.julialang.org/t/change-line-length-in-legend-with-plots/86219>\
**Category:** Visualization\
**Tags:** plotting, pyplot\
**Created:** [August 23, 2022, 7:15pm UTC](https://discourse.julialang.org/t/change-line-length-in-legend-with-plots/86219 "2022-08-23T19:15:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 23, 2022, 7:43pm UTC](https://discourse.julialang.org/t/change-line-length-in-legend-with-plots/86219/2 "2022-08-23T19:43:49Z")

</div>

You may need to use PyPlot directly:

```julia
using PyPlot()

f = [cos, sin, tan, exp, log, atan]
lw = [3, 2, 1, 1, 3, 2] # line width
ls = ["solid", "solid", "solid", "dashed", "dashed","dotted"] #line_style
x = 0.2 : 0.01: 1.2
fig, ax = PyPlot.plt.subplots()
[ax.plot(x, f.(x), lw=lw, ls=ls, label="$(f)") for (f,lw,ls) in zip(f,lw,ls)]
ax.legend(loc="upper left", fontsize=8)
ax.grid(linestyle=:dotted, color="gray")
PyPlot.plt.ylim(-2, 4)
PyPlot.plt.xlim(extrema(x))
PyPlot.plt.legend(handlelength=8) # legend line length
fig.show()

```

 ![Plots_pyplot_legend_line_length](https://global.discourse-cdn.com/julialang/original/3X/f/3/f31cacc25b6edf33cd48d494e6ce34c510d8783a.png)

---

_[View the full topic](https://discourse.julialang.org/t/change-line-length-in-legend-with-plots/86219)._
