0

I am trying to line plot a function, but I am getting an error. How can I do this?

I am using Enthought Canopy.

In[35] : plt.plot(np.arange(0, nx, 1), Iftarray[:, ny/2])
Out[35]: [<matplotlib.lines.Line2D at 0x8332dd8>]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2536176
  • 19
  • 1
  • 7

2 Answers2

4

Like Sam says in the comment: There is no error here; try:

plt.show()

You'll be surprised :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cenna75
  • 539
  • 1
  • 5
  • 13
  • I am getting this error also...dont know why In[53]: pl.imshow Out[53]: – user2536176 Jul 15 '13 at 15:10
  • 1
    That isn't an error. When you use plt.plot() or plt.anythingthatplots without assigning it to a variable then what it returns is outputted to the terminal. You're seeing that output. However, in this case you have to give your function arguments. pl.imshow doesn't do anything, it's just the name of a function. To see your plot use @cenna75 answer. – seth Jul 15 '13 at 15:19
  • Yes, `.show()` is required initially. Subsequent plots may not need it (even if the plot window is closed). – Peter Mortensen Dec 06 '17 at 17:05
3

As the others said, the output text that you see is expected, not an error. However this information, while useful, does not address the question of why you are not seeing the plot.

If your IPython (Canopy's Python shell) is running in Pylab mode (as it does by default; see the Preferences dialog's Python tab to verify), then a plot window should also have been created. However often, depending on the OS, this plot window will not pop up on top of Canopy. So your first task is to poke around your windows and make sure that it's not really there, but you have not seen it.

If the IPython shell is not running in Pylab mode, then cenna75's response is correct; the plot won't display until you explicitly tell it to.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jonathan March
  • 5,800
  • 2
  • 14
  • 16