Python|使用 plotly 进行地理绘图
地理绘图用于世界地图以及国家下的州。主要由数据分析师用于检查农业出口或可视化此类数据。
plotly是一个Python库,用于设计图形,尤其是交互式图形。它可以绘制各种图形和图表,如直方图、条形图、箱线图、散布图等等。它主要用于数据分析和财务分析。 plotly是一个交互式可视化库。
cufflink与 pandas 连接以直接创建数据帧的图形和图表。 choropleth用于描述美国的地理绘图。 choropleth 用于绘制世界地图等等。
安装命令:
pip install plotly
下面是实现:
# Python program to plot
# geographical data using plotly
# importing all necessary libraries
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
# some more libraries to plot graph
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot
# To establish connection
init_notebook_mode(connected = True)
# type defined is choropleth to
# plot geographical plots
data = dict(type = 'choropleth',
# location: Arizoana, California, Newyork
locations = ['AZ', 'CA', 'NY'],
# States of USA
locationmode = 'USA-states',
# colorscale can be added as per requirement
colorscale = 'Portland',
# text can be given anything you like
text = ['text 1', 'text 2', 'text 3'],
z = [1.0, 2.0, 3.0],
colorbar = {'title': 'Colorbar Title Goes Here'})
layout = dict(geo ={'scope': 'usa'})
# passing data dictionary as a list
choromap = go.Figure(data = [data], layout = layout)
# plotting graph
iplot(choromap)
输出: