Pyecharts绘制热力图 & MATLAB绘制不同投影模式(如保面积、保距离、保角度)的地图

 热力图

所需部分数据如下:我们只需要其中一小部分

timelatitudelongitudedepthmagmagTypenstgapdminrmsnetidupdatedplacetypehorizontalErrordepthErrormagErrormagNststatuslocationSourcemagSource
2018-05-09T10:41:45.750Z36.990271.3687111.936.2mww190.5861.03usus1000e19e2018-05-11T12:36:01.367Z36km NW of Ishkashim, Tajikistanearthquake64.30.06622reviewedusus
2018-05-09T07:57:55.250Z-5.8916151.7962106mww421.7280.95usus1000e17w2018-05-09T20:46:20.040Z177km SSW of Kokopo, Papua New Guineaearthquake6.31.60.07119reviewedusus
2018-05-05T06:19:04.590Z14.4969123.931217.876.1mww297.5561.05usus1000dym92018-05-11T12:30:01.364Z56km NNW of Pandan, Philippinesearthquake7.74.10.07119reviewedusus
2018-05-04T22:32:54.370Z19.3127-154.9982.066.9mww2120.1151.49usus1000dyad2018-05-12T08:07:27.820Z19km SSW of Leilani Estates, Hawaiiearthquake5.53.60.05631reviewedhvus
2018-05-02T06:32:48.880Z-24.2596-111.654106mww383.5141.33usus1000dw7i2018-05-03T16:59:41.040ZEaster Island regionearthquake9.71.70.07119reviewedusus
2018-04-19T21:09:17.000Z-42.779742.1877106mww2015.6380.83usus1000dnuj2018-04-20T17:56:29.759ZPrince Edward Islands regionearthquake9.61.70.04254reviewedusus
2018-04-10T10:19:34.030Z-30.9862-71.556676.086.2mww960.3181.17usus2000dxfc2018-05-04T21:11:02.817Z54km SW of Ovalle, Chileearthquake7.35.40.04744reviewedusus
2018-04-07T05:48:40.010Z-5.8382142.531418.076.3mww195.7960.84usus2000dvwq2018-05-12T05:57:19.008Z84km WSW of Porgera, Papua New Guineaearthquake7.130.06523reviewedusus
2018-04-05T03:53:38.410Z6.8325126.7785346mww171.2130.82usus2000dus52018-05-03T04:46:16.441Z43km ESE of Tarragona, Philippinesearthquake7.31.80.0627reviewedusus
2018-04-02T13:40:34.840Z-20.6588-63.00585596.8mww165.320.99usus1000dce22018-04-18T16:27:09.697Z11km NNE of Carandayti, Boliviaearthquake6.71.90.04743reviewedusus
2018-04-02T05:57:35.680Z-24.719-176.887926.1mww204.6031.15usus1000dcbs2018-05-10T12:39:36.537ZSouth of the Fiji Islandsearthquake7.51.80.04548reviewedusus
2018-03-29T21:25:36.790Z-5.5321151.4999356.9mww181.4871.02usus1000db402018-05-05T02:10:06.770Z150km E of Kimbe, Papua New Guineaearthquake6.61.80.05730reviewedusus
2018-03-26T09:51:00.430Z-5.5024151.4025406.7mww151.5071.18usus1000d9372018-05-08T12:55:32.565Z139km E of Kimbe, Papua New Guineaearthquake6.50.80.04940reviewedusus
2018-03-25T20:14:47.710Z-6.6247129.81381696.4mww131.9971.08usus1000d8xh2018-04-29T13:09:39.329Z221km NW of Saumlaki, Indonesiaearthquake6.50.70.03387reviewedusus
2018-03-24T19:58:33.380Z-45.778396.0692106mww2917.7810.75usus1000d8ny2018-04-21T00:01:03.800ZSoutheast Indian Ridgeearthquake10.11.70.05433reviewedusus
2018-03-24T11:23:32.050Z-5.4959151.4971336.3mww195.3610.95usus1000d8k92018-04-01T05:50:17.694Z150km E of Kimbe, Papua New Guineaearthquake7.11.30.04842reviewedusus
2018-03-08T17:39:51.100Z-4.3762153.199622.866.8mww161.0491.05usus1000d1kv2018-04-18T14:54:19.326Z21km ENE of Taron, Papua New Guineaearthquake6.530.04645reviewedusus
2018-03-06T14:13:07.650Z-6.3043142.611620.496.7mww195.4570.97usus2000dcx12018-04-26T17:23:17.142Z113km SW of Porgera, Papua New Guineaearthquake5.32.70.03868reviewedusus

 Pyecharts代码参数可参考官方文档:地理图表 - pyecharts - A Python Echarts Plotting Library built with love.

其中比较关键的是,分别是标记的大小,每个点模糊的大小,是否启用大规模线图的优化,每个点的大小

symbol_size=4, blur_size=15,is_large= True,point_size=8

效果图:

此外如果想要绘制其他地区甚至某省市的地图,只需将maptype更改即可

参数在github上可找到:

pyecharts/pyecharts/datasets/map_filename.json at master · pyecharts/pyecharts (github.com)

 源代码:

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
import pandas as pd
from pyecharts.globals import GeoType

def test_geo():
    g = Geo(init_opts=opts.InitOpts(width="1600px", height="1000px"))
    g.add_schema(maptype="world_china_provinces")

    # 1. 从 CSV 文件中读取数据
    df = pd.read_csv('all_2000s_M6plus.csv')

    # 2. 提取经纬度和震级信息
    data_pair = []
    for index, row in df.iterrows():
        longitude = row['longitude']  # 假设经度列名为 'longitude'
        latitude = row['latitude']    # 假设纬度列名为 'latitude'
        magnitude = row['mag']  # 假设震级列名为 'magnitude'

        print(index)
        print(longitude)
        print(latitude)
        print(magnitude)

        # 将经纬度和震级组织成元组,添加到 data_pair 列表中
        g.add_coordinate(index, longitude, latitude)

        data_pair.append((index, magnitude))

    # 将数据添加到地图上
    g.add('', data_pair, type_=GeoType.HEATMAP, symbol_size=4, blur_size=15,is_large= True
          ,point_size=8)
    # 设置样式
    g.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 自定义分段 color 可以用取色器取色
    pieces = [
        {'max': 1, 'label': '1以下', 'color': '#50A3BA'},
        {'min': 1.0, 'max': 4.0, 'label': '1-4', 'color': '#3700A4'},
        {'min': 4.0, 'max': 4.5, 'label': '4-4.5', 'color': '#81AE9F'},
        {'min': 4.5, 'max': 5.5, 'label': '4.5-5.5', 'color': '#E2C568'},
        {'min': 5.5, 'max': 6.0, 'label': '5.5-6', 'color': '#FCF84D'},
        {'min': 6.0, 'max': 6.5, 'label': '6-6.5', 'color': '#DD0200'},
        {'min': 6.5, 'max': 7.0, 'label': '6.5-7', 'color': '#DD675E'},
        {'min': 7, 'label': '7以上', 'color': '#D94E5D'}  # 有下限无上限
    ]
    #  is_piecewise 是否自定义分段, 变为true 才能生效

    g.set_global_opts(

        visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces),
        title_opts=opts.TitleOpts(title="分布"),
    )
    return g

g = test_geo()
g.render("geo_heatmap.html")

 MATLAB绘制不同投影种类的地图

数据沿用上表的经纬度数据

各种种类的图表都可以在官方文档中找到,(但是官方文档不是很好找,我阅读这类文档的速度还是有点慢的)

Summary and Guide to Projections - MATLAB & Simulink - MathWorks 中国

 

即我们想更换映射类型只需要将

axesm ('eqaconic', 'Frame', 'on', 'Grid', 'on');

 函数中第一个参数更改成我们所需要的就可以了.

% 读取 CSV 文件中的数据
data = readtable('all_2000s_M6plus.csv'); % 假设 CSV 文件中包含标题行,数据从第二行开始读取

% 提取经纬度数据
latitude = data{:, 2}; % 假设经度列在 CSV 文件中的第二列
longitude = data{:, 3}; % 假设纬度列在 CSV 文件中的第三列

landareas = shaperead('landareas.shp','UseGeoCoords',true);
axesm ('eqaconic', 'Frame', 'on', 'Grid', 'on');
geoshow(landareas,'FaceColor',[1 1 .5],'EdgeColor',[.6 .6 .6]);
% 绘制已知经纬度的散点
lat = 20; % 纬度
lon = 30; % 经度
scatterm(latitude, longitude, 8, 'r', 'filled'); % 标记散点,红色填充

% 添加标签
% textm(lat, lon, '', 'FontSize', 12, 'Color', 'blue');

 eqaconic(albers)如下

 mercator:

 eckert2:

 

  • 18
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值