在一个ip中附加两个有图脱机的ip地址

2024-04-23 11:35:48 发布

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

我有以下数据集:

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

谢谢


Tags: import图形initismodelinenotcf
1条回答
网友
1楼 · 发布于 2024-04-23 11:35:48

以下代码应起作用:

导入库

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

相关问题 更多 >