8

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.

2 Answers 2

13

Modify like this:

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

And run like this:

python test.py
Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.