优秀的编程知识分享平台

网站首页 > 技术文章 正文

利用axe对象绘制地图局部缩放图(下面几种建模对象能通过基本实体工具直接绘制的是)

nanyue 2024-10-14 11:33:09 技术文章 8 ℃

一、Matplotlib的figure和axe对象介绍

Matplotlib的figure定义了一块画布,一块画布包含多个axe,一个axe对象是一个画图区域。它指定了一个有数值范围限制的绘图区域。在一个给定的画布(figure)中可以包含多个axes对象,但是一个axes对象只能在一个画布中使用。它的语法为figure .add_axes(rect)。其中的rect是位置参数,接受一个由4个元素组成的浮点数列表,形如[left,bottom,width,height],它表示添加到画布中的矩形区域的左下角坐标(x,y),以及宽度和高度,数值表示占整个画布的比例。

如下代码:

import matplotlib.pyplot as plt

fig=plt.figure(figsize=(8,5))

ax1=fig.add_axes([0,0,1,1],facecolor="grey")

ax2=fig.add_axes([0.2,0.2,0.5,0.5])

plt.show()

将显示如下:

二、利用axe对象绘制地图局部缩放图

import geopandas as gp

import matplotlib.pyplot as plt


china=gp.read_file("d:/中华人民共和国.json")

chinadata=gp.read_file("d:/中华人民共和国1.json")

boundary=chinadata.iloc[4:5,:]


fig, ax = plt.subplots(figsize=(8,5))

ax.set_xlim(70,140)

ax.set_ylim(15,56)

china.plot(ax=ax)

boundary.plot(ax=ax,edgecolor="red")


ax_child=fig.add_axes([0.688,0.125,0.2,0.2])

ax_child.set_xlim(105,125)

ax_child.set_ylim(1,27)

china.plot(ax=ax_child)

boundary.plot(ax=ax_child,edgecolor="red")

ax_child.set_xticks([])

ax_child.set_yticks([])

plt.show()

Tags:

最近发表
标签列表