Skip to content Skip to sidebar Skip to footer

Why Can't One Set To "false" Specific Axis Ticklabels (ex: Xlabels_top, Ylabels_right) From A Cartopy-geopandas Plot?

I am having serious difficulties in setting to False the xlabels_top and ylabels_right from my Geopandas plot. This geopandas plot is made inside a Geoaxes subplot created with Pla

Solution 1:

The labels belong to the gridliner instance not the axes, you can turn them off there by storing the gridliner returned by the gridlines method and setting top_labels, right_labels as in:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import geopandas as gpd

Geopandas_DF = gpd.read_file('my_file.shp')

# setting projection and Transform
Projection=ccrs.PlateCarree()
Transform = ccrs.Geodetic(globe=ccrs.Globe(ellipse='GRS80'))

Fig, Ax = plt.subplots(1,1, subplot_kw={'projection': Projection})

Geopandas_DF.plot(ax=Ax, transform=Ax.transData)

gl = Ax.gridlines(crs=Projection , draw_labels=True, linewidth=0.5, 
                  alpha=0.4, color='k', linestyle='--')

# For Cartopy <= 0.17
gl.xlabels_top = False
gl.ylabels_right = False# For Cartopy >= 0.18# gl.top_labels = False# gl.right_labels = False

Fig.show()

Solution 2:

I finally managed to solve my problem. I used Ajdawson tips in order to do so. Here is the code with the solution:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import geopandas as gpd

Geopandas_DF = gpd.read_file('my_file.shp')

# setting projection and Transform
Projection=ccrs.PlateCarree()
Transform = ccrs.Geodetic(globe=ccrs.Globe(ellipse='GRS80'))

Fig, Ax = plt.subplots(1,1, subplot_kw={'projection': Projection})

Geopandas_DF.plot(ax=Ax, transform=Ax.transData)

gl = Ax.gridlines(crs=Projection , draw_labels=True,    linewidth=0.5, 
                  alpha=0.4, color='k', linestyle='--')

gl.top_labels = False
gl.right_labels = False
gl.xlabels_top = False
gl.ylabels_right = False

Fig.show()

Post a Comment for "Why Can't One Set To "false" Specific Axis Ticklabels (ex: Xlabels_top, Ylabels_right) From A Cartopy-geopandas Plot?"