Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plt.show() making terminal hang

At the end of the last function I call in one of my programs, I have the following code to plot a simple color plot.

plt.figure() plt.pcolormesh(X,Y,Z) plt.colorbar() plt.show() 

Afterwords I return to main and my program is complete. The plot displays as expected, however when I go to close it using the x button in the corner (on ubuntu), my program doesn't end. It just hangs there with a process running. How can I correct this?

like image 977
user1764386 Avatar asked Nov 26 '12 00:11

user1764386


People also ask

Is PLT show () blocking?

Answer #6: plt. show() and plt. draw() are unnecessary and / or blocking in one way or the other.

Is PLT show () necessary?

Plotting from an IPython shell Using plt. show() in Matplotlib mode is not required.

Does Matplotlib work in terminal?

matplotlib-terminal The library is optimized for Gnome Terminal with Ubuntu Mono font. Nevertheless 'block' and 'braille' renderers should work with most modern terminals.

What is the use of PLT plot ()?

The plot() function is used to draw points (markers) in a diagram. By default, the plot() function draws a line from point to point. The function takes parameters for specifying points in the diagram. Parameter 1 is an array containing the points on the x-axis.


2 Answers

your matplotlib might be running in non-interactive mode for some reason. I am not sure how to prevent that in your local configuration but if you add either this:

plt.ion() 

or this:

matplotlib.interactive(True) 

somewhere at the beginning of your script, it should change the behaviour of your plots.

like image 149
Zak Avatar answered Sep 19 '22 03:09

Zak


For interactive mode, You need this at the head of file:

import matplotlib matplotlib.use("TkAgg") 
like image 31
iceflame Avatar answered Sep 21 '22 03:09

iceflame