使用Cartopy在背景图上绘制阵列

时间:2020-11-07 13:41:20

标签: python numpy matplotlib cartopy

我正在尝试使用Cartopy在背景地图图块上绘制一个numpy数组。包括背景图时,该数组不可见。

我正在使用cimgtgeo_axes.add_image()添加背景地图图块。在使用plt.scatter()绘制点之前,此方法对我有用。我尝试了几种投影(PlateCarree,Mercator和EPSG32630)和地图图块(OSM,GoogleTiles)。该数组包含np.nans和浮点数。

这是我的代码:

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()

我似乎找不到导致问题的原因。有人遇到过这个问题吗,或者有人可以看到我在做什么错吗?

1 个答案:

答案 0 :(得分:1)

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

okButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        for (JTextField txtValue : arrayValues) {
            System.out.println(txtValue.getText());
        }
    }
});

结果:

enter image description here