So I'm trying to write a piece of code that creates a figure, but in order for it to run on the computer that I want it to (school one), I can't use the x-window backend to create the figure. I tried switching the backend use (I have the matplotlib.use('Agg') statement in my code), but whenever it creates the figure, it gives me 3 colorbars on the figure when I just want one. It also gives me the error
UserWarning: This call to 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.
warnings.warn(_use_error_msg)
My code starts like this:
import matplotlib
matplotlib.use('Agg')
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
Any ideas or help?
Matplotlib is a plotting library. It relies on some backend to actually render the plots. The default backend is the agg backend.
You need to install a GUI toolkit, so that Matplotlib can display graphics (outside of Jupyter, where the browser handles display). For example, if you install the pyqt package then PyPlot should automatically use the qt5agg backend. Hope this will work.
When we get the Warning: Matplotlib is currently using agg a non-gui backend we can't see the figures or we can say that visualization of plots is not possible. Basically, this error means that we have to install the GUI backend. GUI stands for the graphical user interface.
Matplotlib's series of pyplot functions are used to visualize and decorate a plot.
Late reply, but I wanted to document this for anyone else.
You're likely using Spyder as your python interface. When you start Spyder it automatically loads those modules, hence the error about how it's already been chosen. There's a link here that explains it: https://groups.google.com/forum/#!topic/spyderlib/tRwgqEAIyvs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With