2015-08-08 52 views
0

我正在使用seaborn factorplot繪製熊貓數據。代碼如下:Seaborn - 美學選項

import seaborn 
import numpy as np 
import pandas as pd 

seaborn.set_style("white") 

fg = seaborn.factorplot(x='Group', y='val', hue='Mean', 
         col='Sex', data=data, kind='bar', ci=68, row='Split', x_order=['Group 1', 'Group 2'], 
         row_order=['Poor','Good'], col_order=['Male', 'Female'], sharex=False, sharey=False, 
         palette='deep', legend_out=False 
         ) 

(fg.set_axis_labels("", "val") 
    .set_titles("{row_name} - {col_name}") 
    .set(ylim=(0, 300)) 
    .despine(left=True) 
) 

下面是一個例子數據框:

groups = ('Group 1', 'Group 2') 
sexes = ('Male', 'Female') 
means = ('Low', 'High') 
split = ('Poor', 'Good') 
index = pd.MultiIndex.from_product(
    [groups, sexes, means, split], 
    names=['Group', 'Sex', 'Mean', 'Split'] 
) 

values = np.random.randint(low=20, high=100, size=len(index)) 
data = pd.DataFrame(data={'val': values}, index=index).reset_index() 

我已經看了,看看有什麼美學選項seaborn有,有幾個是我無法找到參考:

  • 這創建了4個地塊的2x2網格。如何調整每個地塊之間的間距?現在,一切都太靠近了

  • 如何單獨設置單獨標籤的字體大小?我希望某些軸/分類標籤比其他軸線更大

  • 如何完全刪除圖例標題?

  • 使用2x2的地塊網格,是否可以將2個地塊放在同一行中放到同一個地塊上?即連接x軸,刪除右邊陰謀的y軸

  • 是否可以將圖保存爲基於矢量的文件格式?

+0

可以爲您提供您的數據幀的一個片段運行一些測試? –

回答

1
fg = seaborn.factorplot(x='Group', y='val', hue='Mean', 
         col='Sex', data=data, kind='bar', 
         ci=68, row='Split', 
         order=['Group 1', 'Group 2'], 
         row_order=['Poor','Good'], 
         col_order=['Male', 'Female'], 
         sharex=False, sharey="row", 
         palette='deep', legend_out=False 
         ) 

(fg.set_axis_labels("", "val") 
    .set_titles("{row_name} - {col_name}") 
    .set(ylim=(0, 300)) 
    .despine(left=True) 
) 

# Increase space between rows and remove space between cols 
fg.fig.subplots_adjust(hspace=.4, wspace=0) 

# Change some label sizes 
fg.axes[0, 0].title.set(size=16) 
fg.axes[1, 0].yaxis.label.set(size=16) 
plt.setp(fg.axes[0, 1].get_xticklabels(), size=16) 

# Remove the legend title 
fg.axes[0, 0].legend() 

# Save to a vector format 
fg.savefig("figure.svg") 

enter image description here

需要注意的是,除了多餘的線條,我在電話中添加sharey="row"factorplot從而消除y軸蜱

+0

完美,謝謝! – Simon

+0

'sharey ='row''?輝煌! –