Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用cartopy在背景地图上绘制阵列_Python_Numpy_Matplotlib_Cartopy - Fatal编程技术网

Python 使用cartopy在背景地图上绘制阵列

Python 使用cartopy在背景地图上绘制阵列,python,numpy,matplotlib,cartopy,Python,Numpy,Matplotlib,Cartopy,我正在尝试使用cartopy在背景贴图平铺上绘制numpy数组。包含背景贴图时,阵列不可见 我正在使用cimgt和geo\u轴添加背景地图分幅。添加图像()。在使用plt.scatter()绘制点时,此方法对我很有效。我尝试过几种投影(PlateCarree、Mercator和EPSG32630)和地图瓷砖(OSM、Google瓷砖)。数组包含np.nan和float 这是我的密码: import numpy as np import matplotlib.pyplot as plt impor

我正在尝试使用cartopy在背景贴图平铺上绘制numpy数组。包含背景贴图时,阵列不可见

我正在使用
cimgt
geo\u轴添加背景地图分幅。添加图像()。在使用
plt.scatter()
绘制点时,此方法对我很有效。我尝试过几种投影(PlateCarree、Mercator和EPSG32630)和地图瓷砖(OSM、Google瓷砖)。数组包含np.nan和float

这是我的密码:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt

# array creation
array = np.asarray([[1, np.nan, np.nan], [1, 1, 1], [2, 2, 1]])
x_coords = np.asarray([690000, 691000, 692000])
y_coords = np.asarray([4958000, 4959000, 496000])

# create figure
fig = plt.figure(figsize=(8, 6), dpi=100)

# create geo axes
projection = ccrs.epsg(32630)
geo_axes = plt.subplot(projection=projection)

# add open street map background
# when commenting the two following lines, the data array is plotted correctly
osm_background = cimgt.OSM()
geo_axes.add_image(osm_background, 14)

# plot dataset
plt.imshow(
    array,
    origin="upper",
    extent=(x_coords[0], x_coords[1], y_coords[0], y_coords[1]),
    transform=projection,
)

# show plot
plt.show()

我似乎找不到问题的原因。以前是否有人遇到过这种情况,或者有人能看出我做错了什么吗?

您需要一些技巧来揭示所有绘制的特征。下面是更新您的相关代码,以及显示(OSM)背景和阵列图像的输出图

# plot dataset
plt.imshow(
    array,
    origin="upper",
    extent=(x_coords[0], x_coords[1], y_coords[0], y_coords[1]),
    transform=projection,
    alpha=0.25,  # allows the background image show-through
    zorder=10    # make this layer on top
)
# draw graticule and labels
geo_axes.gridlines(color='lightgrey', linestyle='-', draw_labels=True)
结果是: