【发布时间】:2020-10-07 18:50:27
【问题描述】:
我想使用 seaborn 制作双胞胎图,但在某些情况下,条形图最终会出现在图的左侧,而对于大多数其他变量来说这很好。应该修复什么? plot
plt.figure(figsize=(15,5))
ax1 = sns.barplot(x=cat, y="Number of opportunities", data=df)
ax1.set_ylabel("Number of opportunities", fontsize=16)
plt.xticks(
rotation=45,
horizontalalignment='right',
fontweight='light',
fontsize='x-large'
)
color = 'c'
ax2 = ax1.twinx()
ax2 = sns.lineplot(x=cat, y="Win Ratio", data=df, linewidth=2, color=color)
【问题讨论】:
-
Seaborn 对条形图使用分类 x 轴。以及用于线图的数字 x 轴(当数据为数字时)。为了让两者一起工作,您可以将数据框的“cat”列转换为字符串。
df['cat'] = df['cat'].astype(str).
标签: plot seaborn bar-chart linechart