Python是一款优秀的编程语言,具有非常广泛的应用领域。其中,数据分析和可视化是Python的重要应用之一。本篇文章将介绍如何使用Python下的matplotlib库,制作新疆地图,具体操作如下:
# 导入必要的库 import matplotlib.pyplot as plt import matplotlib.patches as mpatches # 用来自定义图例 # 新疆省边界经纬度数据 lng = [73.46, 74.33, 77.9, 78.38, 81.88, 85.57, 87.41, 85.75, 87.86, 88.15, 86.3, 88.31, 89.96, 90.96, 91.39, 93.51, 95.94, 95.77, 94.42, 94.85, 96.26, 95.2, 91.07, 89.73, 88.03, 87.28, 85.46, 85.33, 83.78, 82.65, 80.03, 79.57, 75.3, 74.84, 73.69, 73.46] lat = [39.1, 39.24, 43.11, 43.48, 44.34, 48.41, 49.13, 49.43, 49.09, 47.96, 47.5, 45.42, 45.25, 43.13, 41.8, 40.18, 38.88, 38.49, 38.49, 38.05, 37.09, 35.42, 35.37, 35.28, 36.61, 37.23, 37.24, 37.43, 37.05, 37.1, 36.72, 36.97, 37.8, 38.46, 39.17, 39.1] # 创建画布 fig, ax = plt.subplots() # 绘制区域轮廓 boundary = mpatches.Polygon(xy=list(zip(lng, lat)), fill=False, edgecolor='black', linewidth=0.8) ax.add_patch(boundary) # 去除边框和坐标轴 ax.axis('off') # 设置图形标题 ax.set_title('新疆地图', fontdict={'fontsize': 20}) # 显示图形 plt.show()
使用以上代码即可成功地绘制出新疆地图,其中,经纬度数据确定了新疆省的边界,创建画布后,我们绘制出了这条边界的多边形,并加入到图像中。最后,我们去除了边框和坐标轴,使图像更加美观。