将两个绘图脱机iplot附加到一个iplot中

时间:2018-07-23 08:02:32

标签: python plotly

我有以下数据集:

month   is_member   not_member
0   April   84  7
1   August  292 85
2   July    353 125
3   June    260 35
4   May 238 42
5   November    74  6
6   October 219 29
7   September   288 36

我已经绘制了两个单独的图,但是找不到如何组合它们并在一个图上显示两条线的指导

我了解这可能是一个基本问题,但我会很感激

import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, 
iplot
init_notebook_mode(connected=True)
cf.go_offline()
%matplotlib inline

图1:

trace1 = MPVT.iplot(kind='line',x='month',y='not_member', color='white', 
theme='solar', mode='markers+lines',title='bike demand by month for non- 
members')

graph2:

trace2 = MPVT.iplot(kind='line',x='month',y='is_member', color='gold', 
theme = 'solar', mode='lines')

谢谢

1 个答案:

答案 0 :(得分:1)

下面的代码应该可以工作:

导入库

import datetime
from datetime import date
import pandas as pd
import numpy as np
from plotly import __version__
%matplotlib inline

import plotly.offline as pyo
import plotly.graph_objs as go
from plotly.offline import iplot

import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)

cf.go_offline()

创建示例数据框

df = pd.DataFrame({
    'month': ['April', 'August', 'July', 'June', 'May', 'November', 'October', 'September'],
    'is_member': [84, 292, 353, 260, 238, 74, 219, 288],
    'not_member': [7, 85, 125, 35, 42, 6, 29, 36]
}
)
df

创建情节

df.iplot(kind='line',x='month',y=['not_member', 'is_member'], color=['white', 'gold'], 
theme='solar', mode='markers+lines',title='Bike demand by month')

enter image description here