Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a py file from cmd that contain matplotlib plot

I am trying to run a python file (test.py) from command line in windows that contain a matplotlib plot. The file is running but the plot is only appearing for a fraction of second.

Here is the content of test.py:

import matplotlib.pyplot as plt
plt.plot(range(10))

I am using the following command in cmd:

ipython test.py --matplotlib

The output is

Using matplotlib backend: Qt4Agg

The problem is the plot only appears for a fraction of second.

like image 542
gourxb Avatar asked Mar 24 '14 16:03

gourxb


People also ask

How do I run a .PY file in CMD?

Enter the "python" command and your file's name. For example, if your Python file is named "script", you would type in python script.py here. If your Python file has one or more spaces in its name, you'll place quotation marks around the file name and extension (e.g., python "my script.py" ).

Can you use matplotlib in terminal?

The best use of Matplotlib differs depending on how you are using it; roughly, the three applicable contexts are using Matplotlib in a script, in an IPython terminal, or in an IPython notebook.


1 Answers

Modify like this:

import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()

And run like this:

python test.py
like image 53
wim Avatar answered Sep 19 '22 14:09

wim