matplotlib - Python - legend next to plot and in saved figure -


i have been searching across forum have not been able find answer problem yet.

i want create 2 pie charts next each other, legend next it.

labels = ['0-20', '20-40',  '40-60', '60-80', '80-100', '100-120'] colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue', 'orange', 'grey']  fig, [ax1, ax2] = plt.subplots(1,2) ax1.pie(groen, colors = colors, startangle = 90, counterclock = false) ax1.axis('equal')  ax2.pie(rood, colors = colors, startangle = 90, counterclock = false) ax2.axis('equal') plt.legend(labels, loc = 'best')#, bbox_to_anchor=(0.5, 0), mode = 'expand', ncol = 2) 

i have been trying out quite stuff, unfortunately without results. goes wrong legend not in saved image, can seen below. got white bar , legend in wrong order. want read left right, top bottom.

enter image description here

any welcome ;)

when using following code

import matplotlib.pyplot plt groen = rood = [7,8,12,4,9,5] labels = ['0-20', '20-40',  '40-60', '60-80', '80-100', '100-120'] colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue', 'orange', 'grey']  fig, [ax1, ax2] = plt.subplots(1,2) ax1.pie(groen, colors = colors, startangle = 90, counterclock = false) ax1.axis('equal')  ax2.pie(rood, colors = colors, startangle = 90, counterclock = false) ax2.axis('equal') plt.legend(labels, loc = 8, ncol = 2)  plt.savefig(__file__+".png", bbox_inches="tight") plt.show() 

everthing works expected, guess. note bbox_inches="tight" argument, shrinks or expands figure size such nothing cropped.

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -