gpt4 book ai didi

matplotlib - 如何在 matplotlib 中叠加 shapefile

转载 作者:行者123 更新时间:2023-12-01 10:50:45 24 4
gpt4 key购买 nike

在 matplotlib 中,如何在图外的右上角叠加下面所附的 shapefile(在文件夹中可用)。 enter image description here

最佳答案

banderkat引用的代码:

import matplotlib.pyplot as plt
import Image
import numpy as np

im = Image.open('Jbc4j.jpg')
width = im.size[0]
height = im.size[1]

# We need a float array between 0-1, rather than
# a uint8 array between 0-255
im = np.array(im).astype(np.float) / 255

a = np.random.randint(0,100,100)
b = range(100)
fig = plt.figure(1,figsize=(5, 7), dpi=80, facecolor='w')
ax = fig.add_subplot(111)
ax.scatter(a,b)
fig.canvas.draw()

# With newer (1.0) versions of matplotlib, you can
# use the "zorder" kwarg to make the image overlay
# the plot, rather than hide behind it... (e.g. zorder=10)
fig.figimage(im, fig.bbox.xmax - width, fig.bbox.ymax - height, zorder=0)

# (Saving with the same dpi as the screen default to
# avoid displacing the logo image)
fig.savefig('temp.png', dpi=80)

plt.show()

产生以下结果(图像被裁剪以节省空间)。

zorder = 0

更改 zorder=1 会将图像放在顶部。

zorder = 1

其他有用的引用资料:

关于matplotlib - 如何在 matplotlib 中叠加 shapefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20728529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com