0

I have an array that is 1648 x 2608 (from a GOES-16 image, part of a full disk image).

When using cartopy, I can't create a 1648 x 2608 PNG, with the size of my array.

Instead, it creates a 1648 x 2608 white box with the satellite image inside (smaller than 1648 x 2608).

Without using cartopy, I can easily get a full resolution 1648 x 2608 pixels PNG with the code below:

dpi = 150
fig = plt.figure(figsize=(data1.shape[1]/float(dpi), data1.shape[0]/float(dpi)), dpi=dpi)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax = plt.axis('off')

img = plt.imshow(data1, vmin=0, vmax=1, origin='upper', cmap='gray')

plt.savefig('Test.png', pad_inches=0, dpi=dpi)

This is the result I get: Full Resolution (1648 x 2608) PNG Without Cartopy

However, when using cartopy, I do not get a full resolution image as before:

# Globe parameters
semi_major = file1.variables['goes_imager_projection'].semi_major_axis
semi_minor = file1.variables['goes_imager_projection'].semi_minor_axis
globe = ccrs.Globe(semimajor_axis=semi_major, semiminor_axis=semi_minor)

# Define the Geostationary projection for GOES-16
geos  = ccrs.Geostationary(central_longitude=-75.0, satellite_height=35786023.0, globe=globe)

# Image extent
img_extent = (x.min(), x.max(), y.min(), y.max())

# Figure with the size of the array
dpi = 150
fig = plt.figure(figsize=(data1.shape[1]/float(dpi), data1.shape[0]/float(dpi)), dpi=dpi)

# Define the plot
ax = plt.axes(projection=geos)

# Image Extent
ax.set_extent(img_extent,crs=geos)

# Read a shapefile
shapefile = list(shpreader.Reader('ne_10m_admin_0_countries.shp').geometries())
ax.add_geometries(shapefile, ccrs.PlateCarree(), edgecolor='red',facecolor='none', linewidth=1.5)

# Add gridlines
ax.gridlines(color='white', alpha=0.5, linestyle='--', linewidth=0.5)

# Create the image
img = ax.imshow(data1, vmin=0, vmax=1, origin='upper', extent=img_extent, cmap='gray', transform=geos)

# Save the image
plt.savefig('Teste_Diego.png', pad_inches=0, dpi=dpi)

This is the result I get with cartopy: Image with 1648 x 2608 pixels, however, white bounding box

How can I save a PNG with cartopy with the size of my array, in order to get a full resolution plot?

Note: I could create it with Basemap without any problems, however, I'm trying to migrate to Cartopy.

Thanks!

4

1 回答 1

0

为了完整起见,由于这是在CartoPy 的问题跟踪器上回答的,因此解决方案是要求一个Axes跨越该图的:

ax = plt.axes([0, 0, 1, 1], projection=geos)
于 2019-08-27T20:50:27.290 回答