Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default backend for matplotlib in Jupyter Ipython

Right now the default backend for matplotlib is 'module://ipykernel.pylab.backend_inline'

I want to switch that to TkAGG. I edited the matplotlibrc file in

~/anaconda2/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc/

to add

backend : TkAgg

and It did switch the backend for the python but not in Jupyter.

For now everytime I start a new notebook in Jupyter, I have to do %matplotlib tk, isnt there a nice way to make TkAGG the default backend in Jupyter?

like image 295
kada Avatar asked Jan 11 '18 12:01

kada


People also ask

What is the default backend for matplotlib?

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

How do I check my matplotlib backend?

To check that pylab/pyplot backend of Matplotlib runs inline, we can use get_backend() method. The method returns the name of the current backend.

Which matplotlib backend should I use?

By default, Matplotlib should automatically select a default backend which allows both interactive work and plotting from scripts, with output to the screen and/or to a file, so at least initially, you will not need to worry about the backend.


1 Answers

The question is similar to Automatically run %matplotlib inline in IPython Notebook, except that you want to automatically use TK backend instead of inline backend.

So the idea is to locate you IPython configuration file. See configure IPython. It should be

/.ipython/profile_default/ipython_kernel_config.py

If it doesn't yet exist, create it via > ipython profile create.

Inside this file locate the setting c.InteractiveShellApp.matplotlib and set it to "tk". It should then look like

## Configure matplotlib for interactive use with the default matplotlib backend.
c.InteractiveShellApp.matplotlib = "tk"

Save the file and restart the kernel.

like image 99
ImportanceOfBeingErnest Avatar answered Sep 19 '22 02:09

ImportanceOfBeingErnest