简体   繁体   中英

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.

Modify like this:

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

And run like this:

python test.py

The way I like it

  • You can create a.py file and copy your codes into it (or saving your codes in spyder or jupyter as.py file) and finally click on it.
  • The cmd will be run automatically and your plot will be demonstrated. However, if you have imported some data from your directory (for example C:\Users\PC_NAME ) you have to copy.py file to your directory and only click on it there.
  • The reason clicking on.py file seems more satisfactory for me is because it gives a nice 3D view coming with cursor manipulation for rotation which jupyter does not support for matplotlib (unless you use other means of plotting like: plotly in jupyter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM