matplotlib - Python: Making one legend that spans two subplots -
the basic design i'm looking have 2 scatterplots side side each other, , wanted create 1 legend underneath both subplots spans both of them. rough sketch:
i'm able make plots no problem, i'm having hard time getting legend want. here's sample of code have makes 2 scatter plots (i have more data points this, space, i'm including few):
import numpy np numpy import array import matplotlib.pyplot plt x = [5,10,20,30] med1 = [9.35,15.525,26.1,48.275] med2 = [8.75,14.025,23.95,41.025] iqr1 = [13.5125,19.95,38.175,69.9] iqr2 = [12.05,19.075,35.075,62.875] plt.subplot(121) plt.scatter(x, med1, color='red', alpha=0.5, label='red stuff') plt.scatter(x, med2, color='blue', alpha=0.5, label='blue stuff') plt.xlim([0,35]) plt.ylim([0,75]) plt.xlabel('channel area') plt.ylabel('median') plt.subplot(122) plt.scatter(x, iqr1, color='red', alpha=0.5, label='more red stuff') plt.scatter(x, iqr2, color='blue', alpha=0.5, label = 'more blue stuff') plt.xlim([0,35]) plt.ylim([0,75]) plt.xlabel('channel area') plt.ylabel('iqr')
what's best way make legend appear in figure above?
figlegend( (line1, line2, line3), ('label1', 'label2', 'label3'), 'upper right' )
also @ answer question how position , align matplotlib figure legend?
Comments
Post a Comment