Location of the legend in PyPlot

It doesn’t automatically adjust the axis dimensions unfortunately.

x = 0:0.1:3*pi
y = sin(x)
z = cos(x)
ax = axes()
plot(x,y,label="sin(x)")
plot(x,z,label="cos(x)")
grid("on")
legend(bbox_to_anchor=[1.05,1],loc=2,borderaxespad=0)
ax[:set_position]([0.06,0.06,0.71,0.91])

2 Likes