2017-05-11 193 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