2016-05-03 14 views
1

私の凡例のボックスを小さくして、私の円グラフの左上隅に配置しようとしています。これまでのところ私は持っている: pumsData = pd.DataFrame.from_csv( 'ss13hil.csv')円グラフの伝記matplotlib

pieLabels = ['English Only','Spanish','Other Indo-European','Asian and Pacific Island Languages','Other'] 
plt.pie(pumsData.HHL.value_counts()) 
plt.axis('equal') 
plt.title('Household Languages') 
plt.legend(pieLabels,loc=2,borderpad=0.05) 

私のチャートの出力は次のとおりです。
http://i.stack.imgur.com/WbO4U.png

enter image description here

が、私は希望これは次のようになります。

http://i.stack.imgur.com/cBxLz.png

enter code here 
+0

を求めていますか? – tacaswell

答えて

1

明示的にだけではなくpyplotモジュールから関数を使用して、することができます簡単にアクセスプロットプロパティのオブジェクトとして軸インスタンスを作成する場合。 ax.legend()に引数としてbbox_to_anchor=(0.5,0.90)を入力すると、図の凡例を移動できます。このコードを試してみてください。

import matplotlib.pyplot as plt 

pieLabels = ['English Only', 
      'Spanish', 
      'Other Indo-European', 
      'Asian and Pacific Island Languages', 
      'Other'] 

fig, ax = plt.subplots(1,1,figsize=(4,4)) 

ax.pie([1,2,3,4,5], labels=pieLabels, labeldistance=9999999) 
ax.set(adjustable='box-forced', aspect='equal') 
ax.set_title('Household Languages') 

handles, labels = ax.axes.get_legend_handles_labels() 
ax.legend(handles, labels, prop={'size':6}, 
      bbox_to_anchor=(0.5,0.90), 
      bbox_transform=fig.transFigure) 

plt.show() 

それはこの数字を生成する必要があります:あなたは、フォントを小さくする方法をenter image description here

+0

それは他の人がtho OO APIを提案しているのを見てとてもうれしいです:) – tacaswell

+0

@tcaswell – tom