-
Метод 1: использование функции
ax.legend()с параметромframeon, установленным в значениеFalse:import matplotlib.pyplot as plt # Create a plot plt.plot([1, 2, 3], [4, 5, 6], label='Line 1') plt.plot([1, 2, 3], [2, 4, 1], label='Line 2') # Turn off the legend box frame plt.legend(frameon=False) # Display the plot plt.show() -
Метод 2. Доступ к объекту легенды и непосредственное изменение его свойств:
import matplotlib.pyplot as plt # Create a plot plt.plot([1, 2, 3], [4, 5, 6], label='Line 1') plt.plot([1, 2, 3], [2, 4, 1], label='Line 2') # Get the legend object legend = plt.legend() # Turn off the legend box frame legend.set_frame_on(False) # Display the plot plt.show() -
Метод 3. Использование функции
plt.gca().legend()с параметромframeon, для которого установлено значениеFalse:import matplotlib.pyplot as plt # Create a plot plt.plot([1, 2, 3], [4, 5, 6], label='Line 1') plt.plot([1, 2, 3], [2, 4, 1], label='Line 2') # Turn off the legend box frame plt.gca().legend(frameon=False) # Display the plot plt.show()