Created
October 8, 2019 09:46
-
-
Save MatthieuLoustaunau/5e3a6929573c4d600d0a58119bc0bde9 to your computer and use it in GitHub Desktop.
legend outside plot matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | |
ax.plot(x, i * x, label='$y = %ix$'%i) | |
# Shrink current axis by 20% | |
box = ax.get_position() | |
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) | |
# Put a legend to the right of the current axis | |
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment