Quantcast
Channel: How to specify legend position in graph coordinates - Stack Overflow
Viewing all articles
Browse latest Browse all 12

Answer by Drahoš Maďar for How to specify legend position in graph coordinates

$
0
0

You can change location of legend using loc argument.https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.legend.html?highlight=legend#matplotlib.axes.Axes.legend

import matplotlib.pyplot as pltplt.subplot(211)plt.plot([1,2,3], label="test1")plt.plot([3,2,1], label="test2")# Place a legend above this subplot, expanding itself to# fully use the given bounding box.plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,           ncol=2, mode="expand", borderaxespad=0.)plt.subplot(223)plt.plot([1,2,3], label="test1")plt.plot([3,2,1], label="test2")# Place a legend to the right of this smaller subplot.plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)plt.show()

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>