简体   繁体   English

让seaborn点图用一条线显示NaN数据

[英]let seaborn pointplot show NaN data with a line

I'm trying to plot a dataframe looks like this: 我正在尝试绘制一个数据帧,看起来像这样:

Quarter, score
1890.1, NaN
1890.2, 0.000000
1890.2, 0.000000
1890.2, -0.073413
1890.2, 0.000000
1890.3, NaN
1890.4, NaN
1891.1, NaN
1891.2, NaN
1891.3, NaN
1891.4, NaN
1892.1, NaN
1892.2, 0.000000
1892.3, 0.000000

In order to do error bar plot, I used seaborn pointplot. 为了做误差条形图,我使用了seaborn点图。 My problem is, the NaN values are not shown. 我的问题是,NaN值未显示。 So I get a plot with gaps like this: 所以我得到了这样的差距图: NaN值缺失的图形 Is there any way to let seaborn show the missing data with a line? 有什么方法可以让seaborn用一行显示丢失的数据吗? Thanks a lot for your help! 非常感谢你的帮助!

My code are as follows: 我的代码如下:

a4_dims = (15, 8.27)
fig, ax = plt.subplots(figsize=a4_dims)
ax = sns.pointplot(x="Quarter", y="score", data=df, aspect=2.5, capsize=.5)
plt.xticks(rotation=45)
plt.tight_layout()

Maybe you can try setting join 也许您可以尝试设置加入

'If True, lines will be drawn between point estimates at the same hue level.' “如果为True,则将在相同色调级别的点估计之间绘制线。”

Alternatively, you could use: 或者,您可以使用:

use pandas.DataFrame.fillna 使用pandas.DataFrame.fillna

df['score']=df['score'].fillna(method='ffill')

depending on how you would like the line to be filled you can use 取决于您希望如何填充行,可以使用

ffill: propagate last valid observation forward to next valid bfill: use NEXT valid observation to fill gap 填充:将最后一个有效观察向前传播到下一个有效填充:使用下一个有效观察来填补缺口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM