Change line length in legend with Plots

You may need to use PyPlot directly:

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()

1 Like