Is there a way to ask Basemap not to show the plot?
I am trying to use mpl_toolkits.basemap in python and every time I use a function to plot a drawing like drawcoastlines () or whatever, the program automatically displays the plot on the screen.
My problem is that I try to use these programs later on an external server and it returns "SystemExit: Can't access X Display, is $ DISPLAY set?"
Is there a way to avoid displaying the graph when I use the Basemap function? I just want to save it to a file so that later I can read it from the outside.
My code:
from mpl_toolkits.basemap import Basemap
import numpy as np
m = Basemap(projection='robin',lon_0=0)
m.drawcoastlines()
#m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,120.,10.))
m.drawmeridians(np.arange(0.,360.,60.))
source to share
Use a server Agg
, it doesn't require a graphical environment:
Do this at the very beginning of your script:
import matplotlib as mpl
mpl.use('Agg')
See also the FAQ on Generate images without a window appearing .
source to share
The easiest way is to turn off matplotlib interactive mode.
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
#NOT SHOW
plt.ioff()
m = Basemap(projection='robin',lon_0=0)
m.drawcoastlines()
#m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,120.,10.))
m.drawmeridians(np.arange(0.,360.,60.))
source to share