0

I have two graphs in one plot but for some reason the legend, x-label rotation and tight layout only applies to the 2nd graph and not the first?

figure, axis = plt.subplots(1,2,figsize=(9,7))
x2 = ['A','B','C']
Y1 = [90,80,100]
Y2 = [70,100,200]
axis[0].scatter(x2,Y1, c = 'pink',label='salary')
axis[1].scatter(x2,Y2, c = 'orange',label='overtime')
plt.xticks(rotation = 45)
plt.tight_layout()
plt.legend()

I can duplicate the code and put it underneath the first graph but is there a better way. enter image description here

gboffi
  • 22,939
  • 8
  • 54
  • 85
  • 1
    Please create a [reprex]. – BigBen Nov 03 '22 at 15:28
  • Two possibilities, you place a legend in each axis, `axis[0].legend(), axis[1].legend()` or, more complex, follow [this approach](https://stackoverflow.com/questions/9834452/how-do-i-make-a-single-legend-for-many-subplots/57484812?r=SearchResults&s=1%7C43.4677#57484812) to have a single legend describing both scatter plots. – gboffi Nov 03 '22 at 22:20

0 Answers0