Table of contents
- background
- Heat map based on pyecharts built-in latitude and longitude
- Heat map based on custom latitude and longitude
- Disadvantages of pyecharts library
- The difference between different map coordinate systems
- WGS-84 - World Geodetic System
- GCJ-02 - National Bureau of Survey Coordinates
- BD-09 - Baidu Coordinate System
background
The analysis of provinces and regions is basically involved in the statistical analysis of business data. Data visualization is a powerful tool for data analysis. The data of these provinces and regions are generally visualized with maps, so that some laws can be found clearly.
There are many visualization types of maps, such as: basic geographic map, heat map, path map, ripple map, etc. This article mainly introduces heat map , and the tool used is Baidu open source pyecharts
The simulated data takes the popularity of national tourist attractions during the National Eleventh as an example (fictitious data)
simulated data
Heat map based on pyecharts built-in latitude and longitude
Pyecharts comes with the latitude and longitude of some cities. When drawing a picture, you only need to list the name of the city or province, and it will be automatically displayed on the map. pyecharts will automatically extract the latitude and longitude according to the name of the city or province
After installing the pyecharts package, you can find the corresponding files in the pyecharts package folder city_coordinates.json
, which saves a large number of geographic names and latitude and longitude information.
The general path is as follows: xxxxxx\Lib\site-packages\pyecharts\datasets\city_coordinates.json
城市
Next, use the middle and column of simulated data 热度
to visualize the heat map.
Swipe left and right to view the complete code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
Built-in latitude and longitude
Heat map based on custom latitude and longitude
Because pyecharts city_coordinates.json
stores some commonly used geographic latitude and longitude, if you want to use custom latitude and longitude, pyecharts also supports
下面用模拟数据中 经度
、维度
、热度
列来进行热力图可视化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
自定义经纬度
pyecharts库缺点
没有现成的方法用来直接导入自定义坐标,需要先把自定义坐标写在json文件中,然后再通过加载文件实现导入,而没有一个直接导入自定义坐标的方法,这个可以从源码中看出来,如果有一个 add_coordinate_dict
函数就完美了
缺点
不同地图坐标系区别
我们通常用经纬度来表示一个地理位置,但是由于一些原因,我们从不同渠道得到的经纬度信息可能并不是在同一个坐标系下。
- 高德地图、腾讯地图以及谷歌中国区地图使用的是GCJ-02坐标系
- 百度地图使用的是BD-09坐标系
- 底层接口(HTML5 Geolocation或ios、安卓API)通过GPS设备获取的坐标使用的是WGS-84坐标系
不同的坐标系之间可能有几十到几百米的偏移,所以在开发基于地图的产品,或者做地理数据可视化时,我们需要修正不同坐标系之间的偏差。
WGS-84 - 世界大地测量系统
WGS-84(World Geodetic System, WGS)是使用最广泛的坐标系,也是世界通用的坐标系,GPS设备得到的经纬度就是在WGS84坐标系下的经纬度。通常通过底层接口得到的定位信息都是WGS84坐标系
GCJ-02 - 国测局坐标
GCJ-02(G-Guojia国家,C-Cehui测绘,J-Ju局),又被称为火星坐标系,是一种基于WGS-84制定的大地测量系统,由中国国测局制定。此坐标系所采用的混淆算法会在经纬度中加入随机的偏移。
The state stipulates that all public geographical data in mainland China must be encrypted with at least GCJ-02, which means that the data we get from the products of domestic companies must be encrypted. Most domestic Internet map providers use the GCJ-02 coordinate system, including AutoNavi Maps, Google Maps China, etc.
BD-09 - Baidu Coordinate System
BD-09 (Baidu, BD) is the geographic coordinate system used by Baidu Maps, which adds an additional transformation to GCJ-02 to protect user privacy. The coordinates obtained from Baidu products are all in the BD-09 coordinate system