My legend gets cut off:
If I change
plt.figure(figsize=(6.29, 3.54))
to
plt.figure(figsize=(6.29, 8))
It looks like this:
But I want that the plot stays the same size, it just should go longer vertically so that the full legend will be shown.
What can I do?
CodePudding user response:
Essentially, you have to play with bbox_to_anchor keyboard argument in order to place your legend outside of your axes and add a convenient space.
See
CodePudding user response:
plt.figure(figsize=(6.29, 3.54))
dev_y1= np.array([112.95, 117.62, 43.67, 85.64,51.37])
dev_y2= np.array([21.81 , 42.34, 23.82, 61.67,46.23])
dev4x4real = np.array([30.63 ,61.19 , 35.71, 90.53 , 60.33])
dev_x2= np.array([1,2,3,4,5])
plt.plot(dev_x2,dev_y1, 'ro')
popt, pcov = curve_fit(func, dev_x2, dev_y1)
xFit= np.arange(0.0, 5, 0.01)
plt.plot(xFit, func(xFit,*popt),color='r', linestyle='-',label=f'Ideales DOE 125 \u03bcJ <= 0,3 \u03bcm F(x) = {round(popt[0])} * e^({round(popt[1])}*x)')
plt.ylabel('Herstellungsrate: Mikrostrukturen pro Sekunde')
plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
shadow=True, ncol=1,)
plt.show()
This is my code