2

I am using geopandas to draw a map of Italy.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize = (20,30))

region_map.plot(ax=ax, color='white', edgecolor='black')
plt.xlim([6,19])
plt.ylim([36,47.7])
plt.tight_layout()
plt.show()

And this is the results, after properly defining region_map as a piece of 'geometry' GeoSeries .

map of italy

However, I am unable to modify the figure aspect ratio, even varying figsize in plt.subplots. Am I missing something trivial, or is it likely to be a geopandas issue?

Thanks

Marjan Moderc
  • 2,747
  • 23
  • 44
ale-6
  • 365
  • 5
  • 14
  • Do you have correct CRS? That looks like an issue with projection rather than plotting itself. – martinfleis Jan 30 '19 at 20:03
  • You won't change the aspect ratio by changing the `figsize` (matplotlib will automatically adapt the figsize if that doesn't match the aspect ratio of the plot). What is it exactly that you find wrong in the above figure, and what would you like to see instead? – joris Jan 30 '19 at 21:34

1 Answers1

4

Your source dataset (region_map) is obviously "encoded" in geographic coordinate system (units: lats and lons). It is safe to assume in your case this is WGS84 (EPSG: 4326). If you want your plot to look more like it does in e.g Google Maps, you will have to reproject its coordinates into one of many projected coordinate systems (units: meters) . You can use globally acceptable WEB MERCATOR (EPSG: 3857).

Geopandas makes this as easy as possible. You only need to know the basics of how we deal with coordinate projections in computer science and learning most popular CRSes by their EPSG code.

import matplotlib.pyplot as plt

#If your source does not have a crs assigned to it, do it like this:
region_map.crs = {"init": "epsg:4326"}

#Now that Geopandas what is the "encoding" of your coordinates, you can perform any coordinate reprojection
region_map = region_map.to_crs(epsg=3857)

fig, ax = plt.subplots(figsize = (20,30))
region_map.plot(ax=ax, color='white', edgecolor='black')

#Keep in mind that these limits are not longer referring to the source data!
# plt.xlim([6,19])
# plt.ylim([36,47.7])
plt.tight_layout()
plt.show()

I highly recommend reading official GeoPandas docs regarding managing projections.

Marjan Moderc
  • 2,747
  • 23
  • 44