如何将数据格式化为plotly.iplot所需?

时间:2017-12-19 23:23:19

标签: python

这是我的数据:

enter image description here

我按日期将它们合并: 当我使用iplot时,发生了错误:

enter image description here

2 个答案:

答案 0 :(得分:0)

你需要将plot.ly传递给一个字典,如下所示:

py.iplot({'data': [xyz]})

您放入xyz的内容取决于您想要制作的图表。请参阅Plotly's Getting Started Gide

答案 1 :(得分:0)

可以使用iplot()作为带有以下代码的条形图或线图(使用Jupyter NotebookPython 3编写)来绘制数据。

# Import libraries
import pandas as pd
import numpy as np
import datetime
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)
cf.go_offline()

# Create an example dataframe
df = pd.DataFrame({'issue_d': ['2007-06-01', '2007-07-01', '2007-08-01', '2007-09-01', '2007-10-01'],
                   'loan_amt': [91850.0, 348325.0, 515300, 372950.0, 753225.0]
                  })
# Convert date string to datetime
df['issue_d'] = pd.to_datetime(df['issue_d'])

# Create line plot
df.iplot(kind='line', x='issue_d', y='loan_amt', xTitle= 'Issue date', yTitle= 'Loan amount', title='Loan Amounts', width=4)

enter image description here

# Create bar plot
df.iplot(kind='bar', x='issue_d', y='loan_amt', xTitle= 'Issue date', yTitle= 'Loan amount', title='Loan Amounts')

enter image description here