Answers for "plt legend out side"

3

matplotlib legend out of plot

ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),
          ncol=3, fancybox=True, shadow=True)
Posted by: Guest on July-07-2020
0

plt legend top right outside

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)

fig = plt.figure()
ax = plt.subplot(111)

for i in xrange(5):
    line, = ax.plot(x, i * x, label='$y = %ix$'%i)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),
          ncol=3, fancybox=True, shadow=True)
plt.show()
Posted by: Guest on February-23-2021

Python Answers by Framework

Browse Popular Code Answers by Language