OBJECTIVE
CODE
import pandas as pd
import numpy as np
matplotlib.use('QT4Agg')
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import Normalize
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135,
resolution = 'h', area_thresh = 0.1,
llcrnrlon=-106.65, llcrnrlat=25.83,
urcrnrlon=-93.50, urcrnrlat=36.50)
map.drawcoastlines()
map.drawstates()
map.drawcountries()
map.fillcontinents(color = 'white')
map.drawmapboundary()
plt.show(block = False)
OUTPUT
DEBUG
Apparently changing backend helps , however matplotlib.use('QT4Agg')
yields the following error "Gtk* backend requires pygtk to be installed"
Looked online for solutions, read you had to install PyGTK , however, when installing, I receive the following error: Building PyGTK using distutils is only supported on windows.
(after inputting pip install PyGTK
)
Additionally, despite calling matplotlib.use('QT4Agg')
, I receive the error matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.
matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.
.
ISSUE
matplotlib('QT4Agg')
before importing matplotlib, I receive the error (bullet point #3) listed above? Is this in Jupyter Notebook or something of the sort? Usually you shouldn't be able to do
matplotlib.use('QT4Agg')
import matplotlib
in that order, as matplotlib wouldn't be in the namespace. Change the order, then restart your Jupyter kernel or dump all this into a .py file.
In Jupyter, you should be able to call
%matplotlib qt4
before importing matplotlib to set the backend instead of calling use() .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.