设置调色板时点图不显示线
pointplot not showing line when palette is set
当我在 sns.pointplot()
中使用任何调色板时,无论我是否设置 join=True
或选择任何线型,线条都不会显示,这些点具有调色板颜色,但它们没有连接。应该是这样吗?或者我可以设置其他参数来连接这些点吗?线条可以是一种颜色。
一个选项可能是绘制两个点图,一个使用调色板并显示误差线和点,另一个显示连接线(没有调色板)。
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
#make one plot for the line without points and errorbars
ax = sns.pointplot(x="day", y="tip", data=tips, markers="",
join=True, ci=None, color="k")
#make one plot for the points without the connecting line
ax = sns.pointplot(x="day", y="tip", data=tips,
palette=sns.color_palette())
plt.show()
缺点显然是 seaborn 完全忽略 zorder
并在点的顶部画线。因此,需要在外部使用 zorder 才能获得某种吸引人的结果:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
#make one plot for the line without points and errorbars
ax = sns.pointplot(x="day", y="tip", data=tips, markers="",
join=True, ci=None, color="k")
#make one plot for the points without the connecting line
ax = sns.pointplot(x="day", y="tip", data=tips,
palette=sns.color_palette())
ax.lines[0].set_zorder(2)
for l in ax.lines[1:]:
l.set_zorder(5)
for c in ax.collections:
c.set_zorder(3)
plt.show()
当我在 sns.pointplot()
中使用任何调色板时,无论我是否设置 join=True
或选择任何线型,线条都不会显示,这些点具有调色板颜色,但它们没有连接。应该是这样吗?或者我可以设置其他参数来连接这些点吗?线条可以是一种颜色。
一个选项可能是绘制两个点图,一个使用调色板并显示误差线和点,另一个显示连接线(没有调色板)。
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
#make one plot for the line without points and errorbars
ax = sns.pointplot(x="day", y="tip", data=tips, markers="",
join=True, ci=None, color="k")
#make one plot for the points without the connecting line
ax = sns.pointplot(x="day", y="tip", data=tips,
palette=sns.color_palette())
plt.show()
缺点显然是 seaborn 完全忽略 zorder
并在点的顶部画线。因此,需要在外部使用 zorder 才能获得某种吸引人的结果:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
#make one plot for the line without points and errorbars
ax = sns.pointplot(x="day", y="tip", data=tips, markers="",
join=True, ci=None, color="k")
#make one plot for the points without the connecting line
ax = sns.pointplot(x="day", y="tip", data=tips,
palette=sns.color_palette())
ax.lines[0].set_zorder(2)
for l in ax.lines[1:]:
l.set_zorder(5)
for c in ax.collections:
c.set_zorder(3)
plt.show()