0

How to change the figure width and height when using cartoopy. figsize change only the white space around the figure, yet not the figure itself. Any ideas.

import cartopy.crs as ccrs 
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

def main():
    fig = plt.figure(figsize=(10,10))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([-20, 60, -40, 45], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE)
    ax.add_feature(cfeature.BORDERS, linestyle=':')
    ax.add_feature(cfeature.LAKES, alpha=0.5)
    ax.add_feature(cfeature.RIVERS)

    plt.show()

if __name__ == '__main__':
    main()

this code is found here enter image description here

4

1 回答 1

4

The size of the map can be only defined by its extent through the set_extent() method. Changing the figsize will only affect the white frame around the map axes.

EDIT

I see only one option if you want to enlarge the map without changing its extent: change the projection. Some examples here:

enter image description here enter image description here enter image description here

As you can see, some projection will tend to increase the height, some other will appear wider. You cannot fully control the width/height ratio of the map, but still you can try to see if some projections are better for you.

You can find a list of projection at https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html.

Here is the code that produced the first image:

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(3, 3))

ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertCylindrical())
ax.set_extent([-20, 60, -40, 45])
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.add_feature(cfeature.LAKES, alpha=0.5)
ax.add_feature(cfeature.RIVERS)
ax.set_title('LambertCylindrical')

plt.savefig('LambertCylindrical.png', dpi=100)
于 2018-05-17T14:45:27.697 回答