Python draws the earth

Using the Matplotlib library and the Basemap toolkit:

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

# 创建地图
m = Basemap(projection='mill', llcrnrlat=-90, urcrnrlat=90, llcrnrlon=-180, urcrnrlon=180, resolution='c')

# 绘制海岸线和边界
m.drawcoastlines()
m.drawcountries()

# 填充陆地和海洋颜色
m.fillcontinents(color='gray', lake_color='blue')
m.drawmapboundary(fill_color='blue')

# 绘制经纬度网格线
m.drawmeridians(range(-180, 180, 60), labels=[1, 0, 0, 1])
m.drawparallels(range(-90, 90, 30), labels=[1, 0, 0, 1])

# 显示地图
plt.title('Earth')
plt.show()

First import the Matplotlib and Basemap libraries. A Basemap object is created, and the projection mode, range and resolution of the map are defined by passing parameters. Draw elements such as coastlines, boundaries, fill land and sea colors, and finally draw latitude and longitude gridlines to add a title to the map. Display the map through the plt.show() function.

You can modify the code according to your own needs, you can change the color, projection, resolution, etc. of the map to create your own map

Guess you like

Origin blog.csdn.net/weixin_45331480/article/details/129594556