0

I'm having trouble getting the window for matplotlib to show.

I've downloaded python 3.3, matplotlib for python 3.3, and numpy.

I've also installed python tools for Visual Studio 2012 so I can create python solutions in that environment.

With all that out of the way... I'm running this EXTREMELY simple script:

import numpy as np
import matplotlib.pyplot as plt
import pylab

# Come up with x and y
x = np.arange(0, 5, 0.1)
y = np.sin(x)

# plot the x and y and you are supposed to see a sine curve
plt.plot(x, y)

# without the line below, the figure won't show
pylab.show()

This compiles with no warnings or errors, but only my console window displays; no graph or interactive window ever shows up. I tried running the scrip from the command prompt thinking maybe the visual studio environment was throwing it off, but it still didn't work.

I also tried running with python 2.7 and it also didn't work.

Every tutorial I found confirmed that this should be working. I'm pulling my hair out and would praise any help at this point.

3
  • 1
    Is your question how to get it to work without the show()? You need to turn on interactive mode with plt.ion(). However, this also may not work if you are running this as a script, since the script will end and close you won't have a chance to do anything with the graph. Have you tried testing it in the interactive interpreter? Commented Mar 19, 2013 at 5:35
  • Works for me. Try to put import matplotlib;matplotlib.use('TkAgg') at the top of the code and/or delete the settings at %HOMEDRIVE%%HOMEPATH%\.matplotlib Commented Mar 19, 2013 at 6:16
  • plt.show() works for me Commented May 22, 2017 at 19:31

2 Answers 2

3

You should type

plt.show()

instead.

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

Comments

0

You need to put

plt.figure()

to make the figure window before you start plotting information to it

If you are using a GUI console such as Spyder, make sure you have turned on interactive plots so that it plots to a separate window and not inline into the console

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.