Removing the border around a legend in Python Object-oriented construction

I would like to remove the frame around the legend window. I have found several ways. However, none of them implements them using the "axis method".

The code below gets the result, but I want to know a cleaner, more elegant way, perhaps like ax.legend.draw_frame(False) or something like that. Any ideas if such a method exists without using pylab?

SOLUTION: use 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() 
+6
source share
1 answer

Since @Evert does not want to respond, I will do this to mark it as a solution. But please give him your points.

Use ax.legend(numpoints=1, loc=3, frameon=False) , as suggested by Evert

+3
source

Source: https://habr.com/ru/post/975507/


All Articles