I am trying to use Python and the numpy and matplotlib libraries to do some data analysis and plotting and view my plots, adjust my code accordingly etc. So I need to be able to examine the plot. However, running the script from the command line causes the figure to pop up momentarily then instantly disappear. Another answer suggested to add a raw_input("text here")
line at the end of the program to force python to wait for input and hold the plots open. This does hold the plot windows open for me but the actual plots disappear and I just get an empty gray figure window while python waits for input.
I'm running MAC OS X 10.8.3 and using the terminal v2.3 and my python installation is python 2.7.3
import matplotlib.pylab as plt
import numpy as np
[ .. bunch of calculations .. ]
plt.ion()
plt.figure("Test Figure")
plt.plot(xspace[:],vals[:,50])
raw_input("press key to exit")
You can make a plot in matplotlib, add interactive functionality with plugins that utilize both Python and JavaScript, and then render it with D3. mpld3 includes built-in plugins for zooming, panning, and adding tooltips (information that appears when you hover over a data point).
How to Run Python Code Interactively. A widely used way to run Python code is through an interactive session. To start a Python interactive session, just open a command-line or terminal and then type in python , or python3 depending on your Python installation, and then hit Enter .
Use plt.show
at the end of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With