0

I have looked at this question and also this one. It looks like for me, matplotlib.pyplot.show() shows a figure from python, but not from jupyter console.

matplotlib.matplotlib_fname() returns the same matplotlibrc file location for both.

However, when I try to find the backend being used with matplotlib.rcParams['backend'] jupyter console tells me - 'module://ipykernel.pylab.backend_inline', regardless of which backend I have modified the matplotlibrc file to use.

Python on the other hand, correctly shows the backend I'm using; currently 'TkAgg'.

I installed matplotlib using python -mpip install -U matplotlib.

I'm using the following versions:

  • Windows 10
  • Jupyter console 5.2.0
  • Python 2.7.14
  • IPython 5.5.0

I can make do with using python, but it would be nice to figure this out for jupyter console as well.

1 Answer 1

2

First note that plt.show() works as expected, also in Juypter.

enter image description here

This uses the default 'module://ipykernel.pylab.backend_inline' backend. This backend is set by Jupyter, independently of the rcParams setting.

You may set the backend using matplotlib.use()

import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.show()

or just using IPython magic %matplotlib backendname

%matplotlib tk
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.show()

You may change the backend using pyplot.switch_backend()

plt.switch_backend("TkAgg")
plt.plot([1,2,3])
plt.show()

or using the same IPython magic

%matplotlib tk
plt.plot([1,2,3])
plt.show()

If you want to set the backend to be used by default, see this question: Change default backend for matplotlib in Jupyter Ipython

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.