Reputation: 1161
I have following Python data frame and want to plot using plotly client. How can i plot as a line chart.
Date A B C D E F G
2008-03-18 24.68 164.93 114.73 26.27 19.21 28.87 63.44
2008-03-19 24.18 164.89 114.75 26.22 19.07 27.76 59.98
2008-03-20 23.99 164.63 115.04 25.78 19.01 27.04 59.61
2008-03-25 24.14 163.92 114.85 27.41 19.61 27.84 59.41
2008-03-26 24.44 163.45 114.84 26.86 19.53 28.02 60.09
2008-03-27 24.38 163.46 115.4 27.09 19.72 28.25 59.62
2008-03-28 24.32 163.22 115.56 27.13 19.63 28.24 58.65
2008-03-31 24.19 164.02 115.54 26.74 19.55 28.43 59.2
2008-04-01 23.81 163.59 115.72 27.82 20.21 29.17 56.18
2008-04-02 24.03 163.32 115.11 28.22 20.42 29.38 56.64
2008-04-03 24.34 163.34 115.17 28.14 20.36 29.51 57.49
Date as X-axis and A B C D E F G as Y-axis
Upvotes: 1
Views: 11578
Reputation: 2175
Here is some piece of code to solve this problem. Tried with Jupyter Notebook
import pandas as pd
import cufflinks as cf
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected=True)
df = pd.read_csv('/home/user/data_directory/data.csv')
iplot({
'data':
[{'x': df['Date'],
'y': df[col],
'name': col
} for col in df.columns[1:-1]],
'layout':
{'title':'A, B, C, D, E, F, G Time Series'}
}, show_link=False)
plotly.offline
instead of plotly.plotly
to avoid the necessity of having a plotly account;show_link=False
to hide the link text: Export to plotly >> which usually appear at the bottom right of the Figure.
Upvotes: 1
Reputation: 1005
I'd try using cufflinks with Plotly. Cufflinks binds plotly directly to pandas dataframes.
import cufflinks as cf
import plotly.plotly as py
df.iplot(kind='scatter')
From here: https://plot.ly/ipython-notebooks/cufflinks/
This assumes the Date column is the dataframe index.
If the 'Date' column is not the dataframe index, specify it as the x-axis with x:
df.iplot(x='Date',kind='scatter')
Upvotes: 3