# plotly_week1 **Repository Path**: jiayingb/plotly_week1 ## Basic Information - **Project Name**: plotly_week1 - **Description**: No description available - **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 pandas as pd
from plotly.graph_objs import Scatter, Layout
df = pd.read_csv("cities_mattied.csv")
df.head()
dfc = df.set_index("City")
dfc.head()
[int(x) for x in dfc.columns]
dfc.loc["Beijing",:]
dfc.loc["Beijing",:].name
dfc.loc["Beijing",:].values
dfc.loc["Beijing",:].index
import plotly as py
import plotly.graph_objs as go
trace0 = Scatter(
x=[int(x) for x in dfc.columns], #列表推导将字符串转换成整数
y=dfc.loc["Beijing",:].values
)
BJ= go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Beijing",:].values,
name='北京'
)
GD= go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Guangdong",:].values,
name='广东'
)
SH=go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Shanghai",:].values,
name="上海"
)
FJ=go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Fujian",:].values,
name="福建"
)
py.offline.iplot([BJ,GD,SH,FJ],filename="Bj-Sh-Gd-fj.html")
BJ= go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Beijing",:].values,
name='北京'
)
GD= go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Guangdong",:].values,
name='广东'
)
SH=go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Shanghai",:].values,
name="上海"
)
FJ=go.Scatter(
x=[int(x) for x in dfc.columns],
y=dfc.loc["Fujian",:].values,
name="福建"
)
layout=dict(xaxis=dict(rangeselector=dict(buttons=list([
dict(count=5,
label="5年",
stepmode="backward"),
dict(count=10,
label="10年",
stepmode="backward"),
dict(count=20,
label="20年",
stepmode="backward"),
dict(step="all")
])),
rangeslider=dict(bgcolor="#FFF8DC"),
title='年份'
),
yaxis=dict(title='结婚登记(万对)'),
title='4个城市结婚登记对比'
)
fig = dict(data=[BJ,GD,SH,FJ],layout=layout)
py.offline.iplot(fig, filename = 'output_slider')