question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IPython.embed(), displaying matplotlib histograms

See original GitHub issue

I often use ipython to display an interactive prompt, while matplotlib histograms are shown in the background. An example of this usage is shown below.

#!/usr/bin/env python3

import matplotlib.pyplot as plt

fig,axes = plt.subplots()
axes.plot([1,2,3,4,5],[1,2,1,2,1])
plt.show(block=False)

import IPython; IPython.embed()

The intended behavior is that the histogram is displayed, and can then be interacted with while the ipython interpreter is being used. In recent versions of ipython, the matplotlib plot is displayed, but cannot be interacted with. All mouse interactions with the plot are delayed until I hit Ctrl-D to close the ipython interpreter. I have attempted to use the %matplotlib magic method after getting into the ipython interpreter, but this only causes the plot to disappear.

Going through different versions of ipython available through pip, this issue arose between versions 4.2.1 and 5.0.0.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
takluyvercommented, Apr 26, 2017

The code below works for me. You need to enable mpl integration before drawing the plot, because it calls plt.switch_backend(), which closes any open figures.

#!/usr/bin/env python3

import matplotlib.pyplot as plt
from IPython.terminal.embed import InteractiveShellEmbed

shell = InteractiveShellEmbed()
shell.enable_matplotlib()

fig,axes = plt.subplots()
axes.plot([1,2,3,4,5],[1,2,1,2,1])
plt.show(block=False)

shell()
0reactions
Shivaspace4commented, Oct 5, 2018

any suggestions on the above issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 4. Visualization with Matplotlib - O'Reilly
Matplotlib is a multiplatform data visualization library built on NumPy arrays, and designed to work with the broader SciPy stack. It was conceived...
Read more >
IPython reference — IPython 8.7.0 documentation
pdb, the Python debugger, is a powerful interactive debugger which allows you to step through code, set breakpoints, watch variables, etc. IPython makes...
Read more >
Using matplotlib in a python shell
Call figure() and a figure window pops up, call plot() and your data appears in ... There has been a lot of recent...
Read more >
matplotlib.plot in embedded IPython immediately shows plot ...
I normally import matplotlib in IPython this way: %matplotlib inline import matplotlib.pyplot as plt ax, fig = plt.subplots() plt.plot([[1 ...
Read more >
Plot Histograms Using Pandas: hist() Example - Mode Analytics
This recipe will show you how to go about creating a histogram using Python. Specifically, you'll be using pandas hist() method, which is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found