2017-05-11 74 views
1

我在這裏比較新的編程和全新的功能,所以對我來說很簡單。我在Python中有一個查詢,它返回每週收入,每週爲特定分支「停止」(交付)和「件」(包),可以回到用戶請求的週數。我想用Seaborn打印一張圖,顯示每張圖的相鄰位置,但我也希望能夠編輯這些圖。例如,我不知道如何將Y軸更改爲「收入」而不是「平均(收入)」,而不將其作爲單獨數字。相同的停止和件。試圖改變個別軸上的任何東西似乎都不起作用。另外,如何爲圖形添加標題?我試過了,它似乎忽略了我的代碼。在Seaborn中更換座標軸圖

看到這裏的代碼和它目前正在返回圖像:

customer_rev_df = pd.DataFrame(customer_rev, columns='Week Revenue Pieces Stops'.split()).tail(weeks) 
    print(customer_rev_df.set_index('Week')) 
    sns.set_style(style='whitegrid') 
    fig, axs = plt.subplots(ncols=3, figsize=(16, 6)) 
    ax1 = sns.factorplot(x='Week', y='Revenue', data=customer_rev_df, ax=axs[0]) 
    ax2 = sns.factorplot(x='Week', y='Stops', data=customer_rev_df, ax=axs[1]) 
    ax3 = sns.factorplot(x='Week', y='Pieces', data=customer_rev_df, ax=axs[2]) 
    fig.show() 

Graph as it currently looks

感謝您的幫助,您可以提供!

+0

感謝您的建議,但仍然無法正常工作。它似乎忽略了這些代碼,並且打印出來的圖形完全一樣。仍然顯示平均(收入),平均(停止),平均(件)。任何其他想法? 此外,有關獲得標題的任何建議? – Emac

回答

3

您可以指定使用ax.set_ylabel()

對於一些示例代碼,每個小區不同的標籤:

df = pd.DataFrame({'A':range(0,5), 'B':range(0,5), 'C':range(0,5)}) 
sns.set_style(style='whitegrid') 
fig, axs = plt.subplots(ncols=3) 
ax1 = axs[0].plot(df.A.values) 
ax2 = axs[1].plot(df.B.values) 
ax3 = axs[2].plot(df.C.values) 

axs[0].set_ylabel('Revenue') 
axs[1].set_ylabel('Stops') 
axs[2].set_ylabel('Pieces') 

axs[0].set_title('Revenue') 
axs[1].set_title('Stops') 
axs[2].set_title('Pieces') 

fig.show() 

enter image description here

爲您的代碼,你會想:

customer_rev_df = pd.DataFrame(customer_rev, columns='Week Revenue Pieces Stops'.split()).tail(weeks) 
print(customer_rev_df.set_index('Week')) 
sns.set_style(style='whitegrid') 
fig, axs = plt.subplots(ncols=3, figsize=(16, 6)) 
ax1 = sns.factorplot(x='Week', y='Revenue', data=customer_rev_df, ax=axs[0]) 
ax2 = sns.factorplot(x='Week', y='Stops', data=customer_rev_df, ax=axs[1]) 
ax3 = sns.factorplot(x='Week', y='Pieces', data=customer_rev_df, ax=axs[2]) 

axs[0].set_ylabel('Revenue') 
axs[1].set_ylabel('Stops') 
axs[2].set_ylabel('Pieces') 

axs[0].set_title('Revenue') 
axs[1].set_title('Stops') 
axs[2].set_title('Pieces') 


fig.show() 

也可以迭代標籤列表,例如

labels = ['Revenue','Stops','Pieces'] 
for label, ax in zip(labels, axs): 
    ax.set_ylabel(label) 
    ax.set_title(label) 
+0

太棒了!這工作!非常感謝! – Emac

+0

@Emac很高興聽到它,歡迎您:)如果它解決了您的問題,請不要忘記註冊並接受。乾杯 – Chuck

+0

@Emac另外,對於「全局」標題,使用'plt.suptitle()' – Chuck