2

I have the following dataset:

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

I have plotted two separate graphs but cannot find guidance on how to combine them and show two lines on one graph

I understand this might be a basic question but I would appreciate the help

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

graph1:

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

thank you

1 Answer 1

3

Code below should work:

Import libraries

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

Create sample dataframe

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

Create plot

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.