I would like to remove the frame around the legend box. I found few ways. However, none implement them with "axis method".
The code shown below gets the result but I wish to know a cleaner, more elegant way, perhaps like ax.legend.draw_frame(False)
or something similar. Any ideas if such a way exists without using pylab?
SOLUTION: Make use of ax.legend(numpoints=1, loc=3, frameon=False)
as suggested by Evert
import numpy as np
import matplotlib.pyplot as plt
from pylab import legend
x = np.linspace(1,10, 100)
y = x**3
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(x,y, 'bo', label='Blah!')
lg = legend(numpoints = 1, loc=2)
lg.get_frame().set_alpha(0)
#ax.legend(numpoints = 1, loc=2)
plt.show()
Therefore, we can use bty="n" with the legend function and it will remove the border of the legend.
You can remove the border of the legend by using the argument frameon=False in the call to plt. legend() .
Example 1: By using ax. legend_ = None, legend can be removed from figure in matplotlib.
As @Evert does not wish to answer I will do so in order to mark it as solved. But please give him/her points.
Make use of ax.legend(numpoints=1, loc=3, frameon=False)
as suggested by Evert
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With