Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spyder matplotlib UserWarning: This call to matplotlib.use() has no effect because the backend has already been chosen

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?

like image 963
user3600597 Avatar asked May 04 '14 04:05

user3600597


People also ask

What backend is Matplotlib using?

Matplotlib is a plotting library. It relies on some backend to actually render the plots. The default backend is the agg backend.

How do you solve Matplotlib is currently using AGG which is a non GUI backend so Cannot show the figure?

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.

Is a non GUI backend so Cannot show the figure?

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.

Which of the following method is used for displaying a plot using PyPlot module?

Matplotlib's series of pyplot functions are used to visualize and decorate a plot.


1 Answers

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

like image 119
LGelb Avatar answered Sep 25 '22 00:09

LGelb