Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netgraph plot disappears #14

Closed
barun-saha opened this issue Jun 20, 2019 · 1 comment
Closed

Netgraph plot disappears #14

barun-saha opened this issue Jun 20, 2019 · 1 comment

Comments

@barun-saha
Copy link

When I execute a netgraph example as a Python script, the plot window appears and disappears almost instantly. However, when I execute each line of code in the Python prompt, the plot window stays.

An MWE:

import numpy as np
import matplotlib.pyplot as plt; plt.ion()
import netgraph

graph = [
(0, 1),
(1, 2),
(2, 0)
]

netgraph.draw(graph, node_labels={0: '0', 1: '1', 2: '2'})

The same problem occurs with networkx directed graphs as well.

@paulbrodersen
Copy link
Owner

Hi Barun

What you describe is expected behavior for any python script: once the script terminates, the python process (and any child process thereof) is killed.

So what is happening in your MWE:

  1. You run the script, i.e. a python process is created which evaluates your script line-by-line, and the figure is created. Figure creation spawns a child process that displays the rendered image.
  2. As you are in interactive mode (plt.ion()), figure creation is non-blocking, i.e. the rest of the script is evaluated until you reach the end of file.
  3. At this point, the python parent process is terminated. The OS realizes that the figure is in an orphan child process and kills it as well.

Solution: don't use interactive mode, and force the figure display with plt.show() after netgraph.draw() or equivalent.

Hope that helps.

Best,
Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants