gpt4 book ai didi

python - 将两个 plotly offline iplots 附加到一个 iplots

转载 作者:太空宇宙 更新时间:2023-11-04 02:21:36 24 4
gpt4 key购买 nike

我有以下数据集:

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')

图 2:

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

谢谢

最佳答案

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

导入库

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

创建 plotly

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

关于python - 将两个 plotly offline iplots 附加到一个 iplots,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51474128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com