Can I use mathplotlib?

Nov 17, 2011 at 7:23 PM

Hi,

Can I use mathplotlib with PTVS?  I'm trying to run the example:

  from pylab import plot, show, ylim, yticks
  from matplotlib.numerix import sin, cos, exp, pi, arange

  t = arange(0.0, 2.0, 0.01)
  s1 = sin(2*pi*t)
  s2 = exp(-t)
  s3 = sin(2*pi*t)*exp(-t)
  s4 = sin(2*pi*t)*cos(4*pi*t)
  t = arange(0.0, 2.0, 0.01)
  plot(t, s1, t, s2+1, t, s3+2, t, s4+3, color='k')
  ylim(-1,4)
  yticks(arange(4), ['S1', 'S2', 'S3', 'S4'])
  show()

and pylab is undefined.

Any help will be greatly appreciated.

Charles

Coordinator
Nov 17, 2011 at 7:40 PM

Yes, you can use matplotlib, but you'll need to have a Python distribution that includes PyLab.  I believe EPD (including EPD free), Enthought's distribution, includes everything you need.  In 1.1 alpha we'll also make the plots show up in-line.

Nov 17, 2011 at 8:32 PM

I downloaded Enthought's distribution and tested some examples with their GUI.  Everyting works o.k.
I still cannot run my example shown above.  PTVS cannot find pylab.  Do I need to re-install PTVS?

Charles

Coordinator
Nov 17, 2011 at 8:50 PM

Make sure you're running in the right REPL window.  If you have multiple Python distros installed you'll get multiple REPL windows, one for each installed version of Python.  If you do:

 

import sys

sys.version

 

You should get something like:

'2.7.2 |EPD_free 7.1-2 (32-bit)| (default, Jul 3 2011, 15:13:59) [MSC v.1500 32 bit (Intel)]'

 

 I just tried out your example and it worked fine w/ this version of EPD which shows up as Python 2.7 in my View->Other Windows->...  menu.

Nov 18, 2011 at 2:36 AM

Hi,

Sorry to be such a bother.

I had Python 2.6 and 2.7 on my machine.  I removed both of them and I removed their directories.
I also removed PTVS 1.1, and I made sure that I did not have any Python, or Python tools on my machine,
I then rebooted my machine.

I then installed:

  epd_free-7.1-2-win-x86.msi
  PTVS 1.1 Alpha.msi

I started VS 2010 and loaded my Python example shown in my first message.
When I ran the example program under VS2010, a C:\Python27\python.exe window appeared, and it contained:

Traceback (most recent call last):
  File "C:\Temp\PythonApplication1\PythonApplication1\Program.py", line 2, in <module>
    repl = sys.modules['visualstudio_py_repl'].BACKEND
KeyError: 'visualstudio_py_repl'
Press any key to continue . . .

Any suggestions?

Charles

Coordinator
Nov 18, 2011 at 6:50 PM

It looks more like you're running the code posted at http://pytools.codeplex.com/discussions/267411 then the code you posted here.  The code which includes the "repl = sys.modules['visualstudio_py_repl'].BACKEND" line needs to run inside of the interactive window (View->Other Windows->Python 2.7 Interactive).  The code you posted works in the interactive window but should also work if you paste it into a .py file by its self.

In 1.1 we've also made the inline graphs work automatically in IPython mode (instead of the call to send_image and needing to get the repl module).  To use that mode in EPD free you need to easy_install pyzmq first though.

Nov 21, 2011 at 6:53 PM

I deleted:

    import sys
    repl = sys.modules['visualstudio_py_repl'].BACKEND

and hit the run button.  It now works.

I want to thank everyone for your help.

Charles