我正在使用Plotly并尝试创建子图。其中一个图是来自数据帧多个列的时间序列,另一个图是直方图(以及第三个子图-随机线图)。
我一直在使用以下代码在单个绘图中绘制时间序列(来自df中的多个列)
def pltly_timeseries(df):
import plotly.offline as py
import cufflinks as cf
import pandas as pd
import numpy as np
py.plot([{
'x': df.index,
'y': df[col],
'name': col
} for col in df.columns], filename='simple-line.html')
及以下代码可绘制带有直方图和折线图的子图,但不确定如何将时间序列图添加到此图
def ptly_multi_subplots3(df):
'''
:param : pass df for histogram
:return:
'''
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(
rows=2, cols=1,
)
fig.add_trace(go.Histogram(x=df),row=1, col=1)
fig.add_trace(go.Line(y=[2, 3, 1]),row=2, col=1)
fig.update_layout(height=700, showlegend=True)
fig.show()
我正在努力解决的问题是如何在将源序列是df的多个列时将时间序列添加到子图中。