【问题标题】:Remove vertical lines in matplotlib seaborn pointplots删除 matplotlib seaborn 点图中的垂直线
【发布时间】:2021-05-13 21:08:54
【问题描述】:

我在 seaborn 中的 Pointplot 样式有问题,并尝试了一切来修复它,但似乎没有任何效果。您可以在下面看到我的原始数据框

    year  künstliche intelligenz   ki  artificial intelligence  ai
0   2000                      28   16                        4   0
1   2001                       0    0                        0   0
2   2002                       0    0                        0   0
3   2003                       4    0                        0   0
4   2004                       0    0                        0   0
5   2005                       0    0                        0   0
6   2006                       8    0                        0   0
7   2007                      12    0                        0   0
8   2008                       0    0                        0   0
9   2009                       0    0                        0   0
10  2010                       4    0                        0   0
11  2011                       4    0                        0   0
12  2012                       4    0                        0   0
13  2013                       4    0                        0   0
14  2014                      12    0                        0   0
15  2015                      48   24                        8  48
16  2016                      88   92                        8   4
17  2017                      96   48                        0   0
18  2018                     124  124                        4   0
19  2019                      84  292                        0   0
20  2020                      28    8                        0   0

在这个 DF 上,我运行这些命令并得到下面的结果图

data = data.melt('year', var_name='cols', value_name='vals')

fig, ax = plt.subplots(figsize=(6.3792, 6.3792))
sns.pointplot(x="year", y="vals", hue='cols', data=data, colors=sns.color_palette('colorblind'), scale=0.4,
                 ci=None)
ax.set(yscale='log')
ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
ax.set_yticks([1, 2, 4, 8, 16, 32, 64, 128, 256, 512])
ax.set_xticklabels(ax.get_xticklabels(), rotation=30)
plt.show()

我的问题是点系列开始和结束处 X 轴的垂直线。
有没有办法去掉这些竖线?

【问题讨论】:

  • 对于任何想知道问题的人是 DF 中的 0。显然你应该用 np.nan 填充它们

标签: python matplotlib seaborn


【解决方案1】:

这些垂直线代表置信水平,如sns.pointplot 的文档中所述。 如果您不想在图表中显示它们,请查看sns.lineplot

【讨论】:

  • 感谢您的评论,我首先使用了线图。问题是线图不会显示没有连接的单点(例如,2003 年的蓝点不会显示)
猜你喜欢
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 2012-08-01
  • 2018-01-07
  • 1970-01-01
  • 2019-11-22
  • 2021-10-25
  • 2023-04-10
相关资源
最近更新 更多