首页 > 解决方案 > Geopandas 彩色地图未正确显示

问题描述

我有 3 个使用过的数据:

  1. df_prov = 有省和计数列
  2. geojson
  3. df_join = 有省、计数和几何(来自geoj​​son)

这是数据预览: 在此处输入图像描述


    0   Sumatera Utara  7430
    1   Jawa Barat  6192
    2   Jakarta Raya    4635
    3   Banten  2351
    4   Jawa Timur  1383
    5   Jawa Tengah 840
    6   Riau    782
    7   Sumatera Selatan    526
    8   Sumatera Barat  490
    9   Bali    459
    10  Lampung 379
    11  Aceh    377
    12  Kalimantan Timur    266
    13  Sulawesi Selatan    241
    14  Kepulauan Riau  230
    15  Yogyakarta  193
    16  Jambi   186
    17  Bengkulu    133
    18  Sulawesi Utara  109
    19  Bangka Belitung 98
    20  Kalimantan Barat    81
    21  Nusa Tenggara Timur 71
    22  Papua   55
    23  Sulawesi Tengah 54
    24  Kalimantan Utara    37
    25  Maluku  37
    26  Sulawesi Tenggara   33
    27  Kalimantan Tengah   31
    28  Kalimantan Selatan  30
    29  Nusa Tenggara Barat 21
    30  Sulawesi Barat  16
    31  Gorontalo   11
    32  Papua Barat 10
    33  Maluku Utara    8

这是一个省和计数的列表,它表明苏门答腊北方的计数是最多的。

但是当我绘制它时,它表明 Kalimantan timur 具有最暗的值,而不是 sumatera utara。

这是代码:[绘图代码2


    # set a variable that will call whatever column we want to visualise on the map
    values = 'Count'
    # set the value range for the choropleth
    vmin, vmax = 0,100
    # create figure and axes for Matplotlib
    fig, ax = plt.subplots(1, figsize=(30, 10))
    # remove the axis
    ax.axis('off')
    # add a title
    title = 'Data Persebaran per Provinsi'
    ax.set_title(title, fontdict={'fontsize': '25', 'fontweight' : '3'})
    # create an annotation for the data source
    ax.annotate('Source: Laporan per Juni - November',xy=(0.1, .08),  xycoords='figure fraction', horizontalalignment='left', verticalalignment='top', fontsize=12 ,color='#555555')
    
    # norm = mpl.colors.Normalize(vmin=0, vmax=1000) 
    # Create colorbar as a legend
    sm = plt.cm.ScalarMappable(cmap='RdBu', norm=plt.Normalize(vmin=vmin, vmax=vmax))
    # add the colorbar to the figure
    cbar = fig.colorbar(sm)
    # create map
    df_join.plot(column=values, cmap='RdBu', linewidth=0.8, ax=ax, edgecolor='0.8', norm=plt.Normalize(vmin=vmin, vmax=vmax))

这是地图: 在此处输入图片描述

你能帮我看看并告诉我代码有什么问题吗?提前致谢!

标签: pythonmatplotlibgeopandas

解决方案


推荐阅读