0

I am using vscdoe for python. When I do:

from matplotlib import pyplot

fig, ax = pyplot.subplots()

it will give me a blank plot. However, when I use

ax.plot([1, 2, 3], [1, 4, 6])

in subsequent block, I got a

<matplotlib.lines.Line2D at 0x7f9f118e68b0>

My question is: how can I get the vscode print my plot? Thanks.

2
  • Have you tried pyplot.show()? Commented Jul 5, 2020 at 1:13
  • sorry for the delay, thanks for the answer. Commented Jul 17, 2020 at 2:36

4 Answers 4

1

You need to use plt.show() right now you're not printing any of your graph out.

Example:

import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 6])
plt.show() # this line displays your graph

Customize the graph

Now that you know how to print out the graph you could add a title and axises labels.

plt.ylabel('some numbers') # y-axis title
plt.xlabel('other numbers') # x-axis title
plt.title('My Graph') # main title
plt.show() 

Output

enter image description here

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

Comments

1

You forgot to add pyplot.show():

from matplotlib import pyplot

fig, ax = pyplot.subplots()

ax.plot([1, 2, 3], [1, 4, 6])

pyplot.show()

Output:

enter image description here

Comments

0
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [1, 4, 6])

plt.show()

1 Comment

Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.
0

Here is how I usually do it. It prints out in a nice size!

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(10, 8))

ax.plot([1, 2, 3], [1, 4, 6])

plt.show()

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.