Home > Enterprise >  How to remove the frame and axes around a Cartopy/Matplotlib plot?
How to remove the frame and axes around a Cartopy/Matplotlib plot?

Time:12-08

All of a sudden, probably after some module update, I get an extra box/frame with x (0,1) and y (0,1) axes around my Cartopy map. How do I remove this?

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

#Set the projection information
proj = ccrs.NorthPolarStereo(true_scale_latitude = 75)
#Create a figure with an axes object on which we will plot. Pass the projection to that axes.
fig, ax = plt.subplots(figsize=(8,6))
ax = plt.axes(projection=proj)
ax.coastlines('10m')
ax.set_extent([-180, 180, 65, 90], crs=ccrs.PlateCarree())

Weird extra frame around the Cartopy plot

I have tried:

ax.axis('off')
right_side = ax.spines["right"]
right_side.set_visible(False)
plt.box(False)
plt.xticks([])
plt.yticks([])
plt.box(on=None)

Any other ideas would be highly appreciated.

This is a similar issue to: How to remove the frame around my Cartopy/Matplotlib plot

CodePudding user response:

This solves the issue:

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

fig,ax = plt.subplots(figsize=(8,6), subplot_kw={"projection": ccrs.NorthPolarStereo(true_scale_latitude = 75)})
    ax.coastlines('10m')
    ax.set_extent([-180, 180, 65, 90], crs=ccrs.PlateCarree())

CodePudding user response:

My first ever answer here. This clears projection border and won't spill over if you have multiple Axes(ax1, ax2)

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

#Set the projection information
proj = ccrs.NorthPolarStereo(true_scale_latitude=75)
#create fig,  add 1 or more subplots and declare projection frameon status
fig = plt.figure(figsize=(8, 6), )
ax = fig.add_subplot(projection=proj, frameon=False)
ax.coastlines('10m')
ax.set_extent([-180, 180, 65, 90], crs=ccrs.PlateCarree())
  • Related