1

I am getting started with package Cartopy for Python. I would like to display the map of Hungary with the help of package Cartopy. I'm using the following code.

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


def main():
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([20, 10, 20, 30], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE)
    ax.add_feature(cfeature.BORDERS)
    ax.add_feature(cfeature.LAKES, alpha=1, color="blue")
    ax.add_feature(cfeature.RIVERS)

    plt.show()


if __name__ == "__main__":
    main()

What I don't understand is how the coordinates in ax.set_extent([5, 16, 46.5, 56] work. These are the coordinates for Germany, I found them on the web. I've looked up the longitude/latitude for Germany, and these numbers in the code has nothing to do with them. I would be glad if somebody could explain these coordinates and give the coordinates for Hungary. Thank you.

swatchai
  • 17,400
  • 3
  • 39
  • 58

1 Answers1

0

I figured it out. The image which can be created with the code below shows of longitude/latitued with negative/positive. ax.set_extent([x_0, x_1, y_0, y_1] first defines the x parallel range and then the y parallel range.

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
plt.figure(figsize=(18, 12))
map = plt.axes(projection=ccrs.PlateCarree())
grid_lines = map.gridlines(draw_labels=True)
map.coastlines()