You are on page 1of 9

PHÂN TÍCH DỮ LIỆU

KINH DOANH
GV: Võ Hoà ng Kim An
Trực quan hoá dữ liệu
Geographical plotting
Giới thiệu Geographical plotting

• Geographical plotting rấ t thá ch thứ c, vì dữ liệu


có nhiều dạ ng khá c nhau
• Chú ng ta sẽ sử dụ ng plotly để trự c quan hoá
dữ liệu
• Matplotlib cũ ng có phầ n mở rộ ng basemap để
vẽ biểu đồ dạ ng này
Giới thiệu chart_studio

• Đến terminal hoặ c command Prompt và nhậ p


dò ng lệnh sau để cà i đặ t Matplotlib:
conda install -c plotly chart-studio
(và o Anaconda Prompt)
Hoặ c
pip install chart-studio
(Và o Command Prompt)
Giới thiệu Geographical plotting

• import chart_studio.plotly as py
• import plotly.graph_objs as go
• from plotly.offline import download_plotlyjs,
init_notebook_mode, plot, iplot
Giới thiệu chart_studio
• Tạ o dictionary tên “data,” sử dụ ng hà m **dict()**
• type = ‘choropleth’
• location = [list tên củ a cá c bang]
• locationmode = ‘USA-states’
• colorscale =
• Mộ t trong cá c mà u: 'pairs' | 'Greys' | 'Greens' | 'Bluered' | 'Hot' | 'Picnic' |
'Portland' | 'Jet' | 'RdBu' | 'Blackbody' | 'Earth' | 'Electric' | 'YIOrRd' | 'YIGnBu'
• text= list hoặ c array cá c nộ i dung muố n thể hiện trên mỗ i điểm
• z= array cá c giá trị trên cộ t mà u
• colorbar = {'title’:Tên củ a cộ t mà u'}
data = dict(type = 'choropleth',
locations = ['AZ','CA','NY'],
locationmode = 'USA-states’,
colorscale= 'Portland',
text= ['text1','text2','text3'],
z=[1.0,2.0,3.0],
colorbar = {'title':'Colorbar Title’})
layout = dict(geo = {'scope':'usa’})
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap)
df = pd.read_csv('2011_US_AGRI_Exports')
data = dict(type='choropleth',
colorscale = 'ylorrd',
locations = df['code'],
z = df['total exports'],
locationmode = 'USA-states',
text = df['text'],
marker = dict(line = dict(color = 'rgb(255,255,255)',width = 2)),
colorbar = {'title':"Millions USD"})
layout = dict(title = '2011 US Agriculture Exports by State',
geo = dict(scope='usa',
showlakes = True,
lakecolor = 'rgb(85,173,240)’))
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap)
df = pd.read_csv('2014_World_GDP’)
data = dict(
type = 'choropleth',
locations = df['CODE'],
z = df['GDP (BILLIONS)'],
text = df['COUNTRY'],
colorbar = {'title' : 'GDP Billions US’},)
layout = dict( title = '2014 Global GDP’,
geo = dict(showframe = False, projection = {'type':'mercator’}))
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap)

You might also like