改变Seaborn中的轴图

时间:2017-05-11 19:44:16

标签: python matplotlib seaborn

我对编程和全新的比较陌生,所以对我来说很容易。我在Python中有一个查询,它返回每周特定分支的每周收入,“停止”(交付)和“件”(包),并返回用户请求的周数。我想用Seaborn打印一个图形,显示彼此相邻的每个图,但我也希望能够编辑这些图。例如,我无法弄清楚如何将Y轴更改为“收入”而不是“平均(收入)”而不将其作为单独的数字。停止和碎片相同。试图改变各个轴上的任何东西似乎都不起作用。另外,如何为图形添加标题?我试过了,似乎忽略了我的代码。

请参阅此处的代码以及当前返回的图片:

    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

感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:3)

您可以使用@PersistenceContext

为每个地图指定不同的标签

对于一些示例代码:

ax.set_ylabel()

enter image description here

对于您的代码,您需要:

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()

也可以遍历标签列表,例如

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()