关于Python绘制世界地图的问题!


import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Map

df=pd.read_excel('countrytest.xlsx',header=0)
country=pd.DataFrame(df['Country'])
value=pd.DataFrame(df['Publication'])

c = (
    Map()
    .add("",[list(z) for z in zip(country, value)], "world",is_map_symbol_show=False,) 
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))

    .set_global_opts(
        title_opts=opts.TitleOpts(title="世界地图"),
        visualmap_opts=opts.VisualMapOpts(max_=500,)
    )
.render("map_world.html")
)

我这样写出来,做出来的图没有显示国家的数据,该如何解决呢?

img

img

回答不易 求求您采纳哦

您可以尝试检查数据格式是否正确,并尝试使用不同的可视化工具包,例如Basemap、Geopandas等。此外,你可以在绘制地图时使用更详细的地图数据,以获得更准确的结果。

以下是一个使用Basemap绘制世界地图的示例代码:

import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

df = pd.read_excel('countrytest.xlsx',header=0)
country = list(df['Country'])
value = list(df['Publication'])

fig = plt.figure(figsize=(10, 8))
m = Basemap(projection='mill', llcrnrlat=-90, urcrnrlat=90, llcrnrlon=-180, urcrnrlon=180, resolution='c')
m.drawcoastlines()
m.fillcontinents(color='white', lake_color='aqua')
m.drawmapboundary(fill_color='aqua')
m.drawcountries(linewidth=0.5)

for i in range(len(country)):
    x, y = m(df.loc[i, 'Lon'], df.loc[i, 'Lat'])
    plt.text(x, y, country[i], fontsize=10, ha='center')

plt.title('World Map')
plt.show()

该示例代码使用Basemap库,通过指定地图投影、经纬度范围和分辨率等参数来创建世界地图,并使用Pandas读取数据后将国家名称和值传递给Basemap。你可以根据需要调整代码中的参数,以获得所需的地图效果。