iplot奇怪连通YAxis

2024-09-27 07:35:06 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行de命令时:

iplot(df_final[['ds', 'yhat']].set_index('ds').to_iplot())

它绘制了以下图表:

enter image description here

观察结果之间的这种奇怪的联系是什么

仔细观察是:

enter image description here

当我不使用iplot时,它是正确的:

enter image description here


Tags: to命令dfindex图表ds绘制de
1条回答
网友
1楼 · 发布于 2024-09-27 07:35:06

我试图通过添加重复的日期,用连接线在iplot()中重新创建绘图。消除这些行的一个解决方案是在绘图之前按x轴对数据框进行排序,即日期(此处为“ds”列)

# Creating sample data
ds = pd.date_range(pd.datetime.today(), periods=100).tolist()
df = pd.DataFrame(ds, columns=['ds'])
df['yhat'] = np.sin(30*3.14/180)*np.random.randn(100)
df.iplot(x='ds', y='yhat')
# plot link below

Plot without duplicate dates using iplot()

# Create duplicate dates and adding it to the dataframe
df2 = df.append(df.sample(n=5, replace=False)) # this line creates 5 duplicate rows
df2[['ds', 'yhat']].iplot(x='ds', y='yhat')
# plot link below

Plot with duplicate dates and connecting lines using iplot()

# Same plot with plot() works just fine
df2.plot(x='ds', y='yhat')
# plot link below

Plot with duplicate dates using plot()

# Possible solution:
# Sort by date column
df2 = df2.sort_values(by='ds', ascending=True)
# Plot with sorted values
df2[['ds', 'yhat']].iplot(x='ds', y='yhat')
# plot link below

Plot with sorted date column with duplicate dates using iplot()

相关问题 更多 >

    热门问题