python画简便的图-python如何画出漂亮的地图?网友:教教我呗
导入包,创建一副世界地图
不要错过 免费学习Python的机会,快来+688244617
import folium
import pandas as pd
# define the world map
world_map = folium.Map()
# display world map
world_map
python如何画出漂亮的地图?网友:教教我呗
2. 输入经纬度,尺度,在这里我们以旧金山(37.7749° N, 122.4194° W)为例。
# San Francisco latitude and longitude values
latitude = 37.77
longitude = -122.42
# Create map and display it
san_map = folium.Map(location=[latitude, longitude], zoom_start=12)
# Display the map of San Francisco
san_map
python如何画出漂亮的地图?网友:教教我呗
更改地图显示,默认为'OpenStreetMap'风格,我们还可以选择'Stamen Terrain', 'Stamen Toner'等。
# Create map and display it
san_map = folium.Map(location=[latitude, longitude], zoom_start=12,tiles='Stamen Toner')
python如何画出漂亮的地图?网友:教教我呗
3. 读取数据集(旧金山犯罪数据集)
# Read Dataset
cdata = pd.read_csv('https://cocl.us/sanfran_crime_dataset')
cdata.head()
python如何画出漂亮的地图?网友:教教我呗
4. 在地图上显示前200条犯罪数据
# get the first 200 crimes in the cdata
limit = 200
data = cdata.iloc[0:limit, :]
# Instantiate a feature group for the incidents in the dataframe
incidents = folium.map.FeatureGroup()
# Loop through the 200 crimes and add each to the incidents feature group
for lat, lng, in zip(cdata.Y, data.X):
incidents.add_child(
folium.CircleMarker(
[lat, lng],
radius=7, # define how big you want the circle markers to be
color='yellow',
fill=True,
fill_color='red',
fill_opacity=0.4
)
)
# Add incidents to map
san_map = folium.Map(location=[latitude, longitude], zoom_start=12)
san_map.add_child(incidents)
python如何画出漂亮的地图?网友:教教我呗
5. 添加地理标签
# add pop-up text to each marker on the map
latitudes = list(data.Y)
longitudes = list(data.X)
labels = list(data.Category)
for lat, lng, label in zip(latitudes, longitudes, labels):
folium.Marker([lat, lng], popup=label).add_to(san_map)
# add incidents to map
san_map.add_child(incidents)
python如何画出漂亮的地图?网友:教教我呗
6. 统计区域犯罪总数
from folium import plugins
# let's start again with a clean copy of the map of San Francisco
san_map = folium.Map(location = [latitude, longitude], zoom_start = 12)
# instantiate a mark cluster object for the incidents in the dataframe
incidents = plugins.MarkerCluster().add_to(san_map)
# loop through the dataframe and add each data point to the mark cluster
for lat, lng, label, in zip(data.Y, data.X, cdata.Category):
folium.Marker(
location=[lat, lng],
icon=None,
popup=label,
).add_to(incidents)
# add incidents to map
san_map.add_child(incidents)
python如何画出漂亮的地图?网友:教教我呗
7. 读取geojson文件,可视化旧金山市10个不同Neighborhood的边界
import json
import requests
url = 'https://cocl.us/sanfran_geojson'
san_geo = f'{url}'
san_map = folium.Map(location=[37.77, -122.4], zoom_start=12)
folium.GeoJson(
san_geo,
style_function=lambda feature: {
'fillColor': '#ffff00',
'color': 'black',
'weight': 2,
'dashArray': '5, 5'
}
).add_to(san_map)
#display map
san_map
python如何画出漂亮的地图?网友:教教我呗
8. 统计每个区域的犯罪事件数目
# Count crime numbers in each neighborhood
disdata = pd.DataFrame(cdata['PdDistrict'].value_counts())
disdata.reset_index(inplace=True)
disdata.rename(columns={'index':'Neighborhood','PdDistrict':'Count'},inplace=True)
disdata
python如何画出漂亮的地图?网友:教教我呗
9. 创建Choropleth Map (颜色深浅代表各区犯罪事件数目)
m = folium.Map(location=[37.77, -122.4], zoom_start=12)
folium.Choropleth(
geo_data=san_geo,
data=disdata,
columns=['Neighborhood','Count'],
key_on='feature.properties.DISTRICT',
#fill_color='red',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
highlight=True,
legend_name='Crime Counts in San Francisco'
).add_to(m)
m
python如何画出漂亮的地图?网友:教教我呗
10. 创建热力图
# let's start again with a clean copy of the map of San Francisco
san_map = folium.Map(location = [latitude, longitude], zoom_start = 12)
# Convert data format
heatdata = data[['Y','X']].values.tolist()
# add incidents to map
HeatMap(heatdata).add_to(san_map)
san_map
python如何画出漂亮的地图?网友:教教我呗
实现效果如下图所示 。
python如何画出漂亮的地图?网友:教教我呗
python画简便的图-python如何画出漂亮的地图?网友:教教我呗相关推荐
- python画简便的图-python中简单易学的绘图:用turtle画太极图
为什么想画太极图呢?因为我儿子不知道是看了哪本书还是哪个电视,竟然特地打印出一张太极图要挂在大门口,我赶紧说祖宗这挂在门外,别人看见了还以为咱家出什么事了,你喜欢就挂自己卧室门口吧,于是这张图就成了他 ...
- python画简便的图-python如何画出漂亮的地图?
推荐一个超好用的python包folium, 专门用于地理数据可视化,官方英文教程教程点击这里,查看本文源代码请点击这里. /> 使用方法很简单,操作如下:导入包,创建一副世界地图 import ...
- python画简便的图-python的pyecharts绘制各种图表详细(附代码)
环境:pyecharts库,echarts-countries-pypkg,echarts-china-provinces-pypkg,echarts-china-cities-pypkg 数据:20 ...
- python画简便的图-python 实现在一张图中绘制一个小的子图方法
有时候为了直观展现图的信息,可以在大图中添加小子图的方式进行数据分析,如下图所示: 具体的代码如下:该图连接了数据库,当然重要的不是数据展示,而是添加子图的方法. import matplotlib. ...
- python能画k线图吗_python画k线图(一天的k线图怎么画)
1.大智慧软件在日线窗口的左上角标有主图的公式名称,(如ma sar bbi )等, 如果不是ma指标,请输入ma,回车.2.如果输入ma后还是没有均线,请按 f7 键,弹出 最好能举个例子的.非常感 ...
- 用python绘制漂亮的图形-python如何画出漂亮的地图?
Python地图可视化库有大家熟知的pyecharts.plotly.folium,其他回答都有介绍,还有稍低调的bokeh.basemap.geopandas,也是地图可视化的利器. 首先介绍下bo ...
- python画地图柱状图_Python 如何画出漂亮的地图?
Python地图可视化库有大家熟知的pyecharts.plotly.folium,其他回答都有介绍,还有稍低调的bokeh.basemap.geopandas,也是地图可视化的利器. 首先介绍下bo ...
- python画指北针_python如何画出漂亮的地图?
python如何画出漂亮的地图? 要画一张好看的地图,数据量的多少.底图的支持程度与选择乃至个人的美学素养是一张好看的地图重要的因素.目前python也有很多能够实现地图可视化的包,这里给大家推荐最基 ...
- python画简便的图-最适合小白学的花色玩Python折线图|画个天气预报
原标题:最适合小白学的花色玩Python折线图|画个天气预报 欢迎关注天善智能 hellobi.com,我们是专注于商业智能BI,大数据,数据分析领域的垂直社区,学习.问答.求职,一站式搞定! 对商业 ...
最新文章
- SAP QM 高阶之Physical Sample Management
- AMBA、AHB、APB、AXI总线介绍和对比
- 基于Linux系统中进程调度分析
- hikaripool连接保持_springboot2的hikari数据库连接池默认配置
- 吴恩达深度学习笔记11-Course4-Week2【深度卷积网络:实例探究】
- shell中取字符串子串的几种方式
- oracle asm 异机挂载,oracle 异机恢复 从asm到文件系统成功实例
- Linux下读取smBIOS源码,Linux下读取SMBIOS信息
- 从没想过会有一个这样的机会|大疆招聘
- 原有ui项目调用qml_从0开始写前端UI框架:概述
- 基于RNN和CTC的语音识别模型,探索语境偏移解决之道
- winsocket(1)
- OpenShift Security (11) - 用RHACS在DevOps的CICD中扫描部署中的安全风险
- redis mysql 集群_Redis(五)、Redis数据库集群相关
- Moon一个无视Linq,无视实体类的设计思路.(不要错过,看了之后, 让我们从此以后不再羡慕linq to entiy!)...
- php如何处理耗时的任务,PHP如何在请求完毕后继续处理耗时任务
- Dxg——C++ 开发笔记整理分类合集【所有的相关记录,都整理在此】
- 【ArcGIS微课1000例】0026:ArcGIS10如何自定义工具条?
- 航班查询接口调用介绍
- 线上连锁线下整合 连锁店电商解决方案