# hw-plotly **Repository Path**: NFUNM049/hw-plotly ## Basic Information - **Project Name**: hw-plotly - **Description**: 第一次plotly作业 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-11-09 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
import plotly as py
import pandas as pd
py.offline.init_notebook_mode()
df = pd.read_csv('zaolin2.csv')
df.columns
dfc = df.set_index('地区')
dfe = dfc
dfe.head()
import plotly as py
import plotly.graph_objs as go
py.offline.init_notebook_mode()
北京 = go.Scatter(
x=[pd.to_datetime('01/01/{y}'.format(y=x), format="%m/%d/%Y") for x in dfe.columns.values],
y=dfe.loc["北京市",:].values,
name = "北京市"
)
天津 = go.Scatter(
x=[pd.to_datetime('01/01/{y}'.format(y=x), format="%m/%d/%Y") for x in dfe.columns.values],
y=dfe.loc["天津市",:].values,
name = "天津市"
)
layout = dict(xaxis=dict(rangeselector=dict( buttons=list([
dict(count=3,
label="3年",
step="year",
stepmode="backward"),
dict(count=5,
label="5年",
step="year",
stepmode="backward"),
dict(count=10,
label="10年",
step="year",
stepmode="backward"),
dict(step="all")
])),
rangeslider=dict(bgcolor="#c3ddff"),
title='年份'
),
yaxis=dict(title='天津与北京近十年造林面积对比'),
title="近十年北京市与天津市2009年-2017年造林面积对比"
)
abc = dict(data=[北京,天津], layout=layout)
py.offline.iplot(abc, filename = "test.html")