Trying to migrate to Python 3.2, Matplotlib 1.2.1

Hello everyone,

After not using Matplotlib for over a year, I'm returning to it. Meanwhile, I have upgraded from Python 2.7 to Python 3.2, and I want to do all of my software development in Python 3 from now on.

My OS is Ubuntu 12.04.1. Python 2.7 is still the default Python for Ubuntu, and many of the Python 3 packages are not offered as official repositories yet. I downloaded Matplotlib 1.2.1, then built it using Python 3. Eventually, I got no build error messages, and proceeded to install. (I always have to pick through dependency problems one error message at a time. I wish there was a better way. The Matplotlib docs could be a little better in this respect.)

When I open a Python3 interpreter, I can import matplotlib. But I am not seeing ANYTHING with commands like plt.show(). It executes, and then returns. No output is generated.

This very short and simple test program of mine used to produce output with Python 2.7 and Matplotlib 1.1.0. But with Python 3 and Matplolib 1.2.1, I am getting nothing...

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
plt.show()

It runs. No error messages are generated. But I don't get a graph. I don't even see a graph flicker on to the screen and disappear an instant later.

Any advice will be appreciated!

Hi John,

does plt.savefig(‘test.png’) work?

If the figure get saved, it can be that you are using a non interactive backend

Cheers

Fra

···

2013/4/18 John Ladasky <john_ladasky@…209…>

Hello everyone,

After not using Matplotlib for over a year, I’m returning to it.

Meanwhile, I have upgraded from Python 2.7 to Python 3.2, and I want to

do all of my software development in Python 3 from now on.

My OS is Ubuntu 12.04.1. Python 2.7 is still the default Python for

Ubuntu, and many of the Python 3 packages are not offered as official

repositories yet. I downloaded Matplotlib 1.2.1, then built it using

Python 3. Eventually, I got no build error messages, and proceeded to

install. (I always have to pick through dependency problems one error

message at a time. I wish there was a better way. The Matplotlib docs

could be a little better in this respect.)

When I open a Python3 interpreter, I can import matplotlib. But I am

not seeing ANYTHING with commands like plt.show(). It executes, and

then returns. No output is generated.

This very short and simple test program of mine used to produce output

with Python 2.7 and Matplotlib 1.1.0. But with Python 3 and Matplolib

1.2.1, I am getting nothing…

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);

y = np.sin(x)

plt.plot(x, y)

plt.show()

It runs. No error messages are generated. But I don’t get a graph. I

don’t even see a graph flicker on to the screen and disappear an instant

later.

Any advice will be appreciated!


Precog is a next-generation analytics platform capable of advanced

analytics on semi-structured data. The platform includes APIs for building

apps and a phenomenal toolset for data science. Developers can use

our toolset for easy data analysis & visualization. Get a free account!

http://www2.precog.com/precogplatform/slashdotnewsletter


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

You will need to make sure you install the gtk packages (both the libraries
and the dev packages) *before* building from source. If it can't find the
dev packages, then it won't build the interactive backend for it. I can't
remember if there are python3 specific packages for gtk (or any other gui
for that matter).

···

On Thu, Apr 18, 2013 at 3:34 AM, John Ladasky <john_ladasky@...209...>wrote:

Hello everyone,

After not using Matplotlib for over a year, I'm returning to it.
Meanwhile, I have upgraded from Python 2.7 to Python 3.2, and I want to
do all of my software development in Python 3 from now on.

My OS is Ubuntu 12.04.1. Python 2.7 is still the default Python for
Ubuntu, and many of the Python 3 packages are not offered as official
repositories yet. I downloaded Matplotlib 1.2.1, then built it using
Python 3. Eventually, I got no build error messages, and proceeded to
install. (I always have to pick through dependency problems one error
message at a time. I wish there was a better way. The Matplotlib docs
could be a little better in this respect.)

When I open a Python3 interpreter, I can import matplotlib. But I am
not seeing ANYTHING with commands like plt.show(). It executes, and
then returns. No output is generated.

This very short and simple test program of mine used to produce output
with Python 2.7 and Matplotlib 1.1.0. But with Python 3 and Matplolib
1.2.1, I am getting nothing...

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
plt.show()

It runs. No error messages are generated. But I don't get a graph. I
don't even see a graph flicker on to the screen and disappear an instant
later.

Any advice will be appreciated!

Thanks to both Francesco Montesano and Benjamin Root. I have done some reading. And I have made some progress, though I am not quite where I want to be yet.

So the problem appears to be that the only backend for which I had suitable Python 3 libraries was agg. It only requires libpng, which I have. I can render a Matplotlib canvas, but it appears that the only output that agg offers is in the form of PNG files to disk. I cannot create a live window on the screen.

Reading more, I realize that the way I was getting GUI output previously (with Python 2.7 and Matplotlib 1.1) was through wxPython. Unfortunately, it appears that wxPython's star is fading, and a Python 3-compatible version will not be written. In fact, wxPython hasn't released a new version in nine months.

The other choices for Matplotlib GUI output on Linux appear to be through GTK, PySide, and PyQt. I am not familiar with GTK, but I know that it is widely-used. Also, GTK appears to be Python 3-compatible, and so that is where I need to go.

I'm going through a trial and error process. Unfortunately, the names of the repositories in Ubuntu are not very helpful. I installed a few GTK and python-gtk related packages that I thought were relevant. On my first build attempt I got no errors, but also, I didn't get a GTKAgg backend. Upon re-reading, I saw that I should modify matplotlib's setup.cfg file to force a GTK build attempt, and to report errors if it fails. That's what it does. In the "optional backend dependencies" section I am not seeing any GTK libraries listed, even though I have installed python-gtk2-dev (2.24.0), python-gobject-2-dev (2.28.6), libgtk2.0-dev (2.24.10), libglib2.0-dev (2.32.3), python-gi-dev (3.2.2), python-gobject-dev (3.2.2), python3-gi (3.2.2), and a few DOZEN packages on which these depend.

If anyone knows the way forward from here, I would appreciate your advice. Thanks again.

wxPython is alive and well and the newest developmental version of it (“Phoenix”) runs on Python 3. It should be released fairly soon. One of the wxPython list regulars mentioned getting his software to run with it, with a few minor issues, just six days ago. So you might want to give Phoenix a try.

Che

···

On Thu, Apr 18, 2013 at 11:03 PM, John Ladasky <john_ladasky@…209…> wrote:

.

Reading more, I realize that the way I was getting GUI output previously

(with Python 2.7 and Matplotlib 1.1) was through wxPython.

Unfortunately, it appears that wxPython’s star is fading, and a Python

3-compatible version will not be written. In fact, wxPython hasn’t

released a new version in nine months.

I have used the TkAgg backend in python2, installing the dependencies by hand. Is this backend not available for python3?

-Sterling

···

On Apr 18, 2013, at 8:03PM, John Ladasky wrote:

Thanks to both Francesco Montesano and Benjamin Root. I have done some
reading. And I have made some progress, though I am not quite where I
want to be yet.

So the problem appears to be that the only backend for which I had
suitable Python 3 libraries was agg. It only requires libpng, which I
have. I can render a Matplotlib canvas, but it appears that the only
output that agg offers is in the form of PNG files to disk. I cannot
create a live window on the screen.

Reading more, I realize that the way I was getting GUI output previously
(with Python 2.7 and Matplotlib 1.1) was through wxPython.
Unfortunately, it appears that wxPython's star is fading, and a Python
3-compatible version will not be written. In fact, wxPython hasn't
released a new version in nine months.

The other choices for Matplotlib GUI output on Linux appear to be
through GTK, PySide, and PyQt. I am not familiar with GTK, but I know
that it is widely-used. Also, GTK appears to be Python 3-compatible,
and so that is where I need to go.

I'm going through a trial and error process. Unfortunately, the names
of the repositories in Ubuntu are not very helpful. I installed a few
GTK and python-gtk related packages that I thought were relevant. On my
first build attempt I got no errors, but also, I didn't get a GTKAgg
backend. Upon re-reading, I saw that I should modify matplotlib's
setup.cfg file to force a GTK build attempt, and to report errors if it
fails. That's what it does. In the "optional backend dependencies"
section I am not seeing any GTK libraries listed, even though I have
installed python-gtk2-dev (2.24.0), python-gobject-2-dev (2.28.6),
libgtk2.0-dev (2.24.10), libglib2.0-dev (2.32.3), python-gi-dev (3.2.2),
python-gobject-dev (3.2.2), python3-gi (3.2.2), and a few DOZEN packages
on which these depend.

If anyone knows the way forward from here, I would appreciate your
advice. Thanks again.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi John,

on Kubuntu Precise the standard repo has at least:

python3-pyqt4

python3-pyside

python3-tk

The first two should enable Qt4Agg backend, the last TkAgg

Fra

···

2013/4/19 Sterling Smith <smithsp@…3304…>

I have used the TkAgg backend in python2, installing the dependencies by hand. Is this backend not available for python3?

-Sterling

On Apr 18, 2013, at 8:03PM, John Ladasky wrote:

Thanks to both Francesco Montesano and Benjamin Root. I have done some

reading. And I have made some progress, though I am not quite where I

want to be yet.

So the problem appears to be that the only backend for which I had

suitable Python 3 libraries was agg. It only requires libpng, which I

have. I can render a Matplotlib canvas, but it appears that the only

output that agg offers is in the form of PNG files to disk. I cannot

create a live window on the screen.

Reading more, I realize that the way I was getting GUI output previously

(with Python 2.7 and Matplotlib 1.1) was through wxPython.

Unfortunately, it appears that wxPython’s star is fading, and a Python

3-compatible version will not be written. In fact, wxPython hasn’t

released a new version in nine months.

The other choices for Matplotlib GUI output on Linux appear to be

through GTK, PySide, and PyQt. I am not familiar with GTK, but I know

that it is widely-used. Also, GTK appears to be Python 3-compatible,

and so that is where I need to go.

I’m going through a trial and error process. Unfortunately, the names

of the repositories in Ubuntu are not very helpful. I installed a few

GTK and python-gtk related packages that I thought were relevant. On my

first build attempt I got no errors, but also, I didn’t get a GTKAgg

backend. Upon re-reading, I saw that I should modify matplotlib’s

setup.cfg file to force a GTK build attempt, and to report errors if it

fails. That’s what it does. In the “optional backend dependencies”

section I am not seeing any GTK libraries listed, even though I have

installed python-gtk2-dev (2.24.0), python-gobject-2-dev (2.28.6),

libgtk2.0-dev (2.24.10), libglib2.0-dev (2.32.3), python-gi-dev (3.2.2),

python-gobject-dev (3.2.2), python3-gi (3.2.2), and a few DOZEN packages

on which these depend.

If anyone knows the way forward from here, I would appreciate your

advice. Thanks again.


Precog is a next-generation analytics platform capable of advanced

analytics on semi-structured data. The platform includes APIs for building

apps and a phenomenal toolset for data science. Developers can use

our toolset for easy data analysis & visualization. Get a free account!

http://www2.precog.com/precogplatform/slashdotnewsletter


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Precog is a next-generation analytics platform capable of advanced

analytics on semi-structured data. The platform includes APIs for building

apps and a phenomenal toolset for data science. Developers can use

our toolset for easy data analysis & visualization. Get a free account!

http://www2.precog.com/precogplatform/slashdotnewsletter


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I'm surprised that you say this as months of work have gone into updating wxPython to make in Python 3 compatible. Please see Index of /Phoenix/snapshot-builds for the latest and greatest.

···

On 19/04/2013 04:03, John Ladasky wrote:

Reading more, I realize that the way I was getting GUI output previously
(with Python 2.7 and Matplotlib 1.1) was through wxPython.
Unfortunately, it appears that wxPython's star is fading, and a Python
3-compatible version will not be written. In fact, wxPython hasn't
released a new version in nine months.

--
If you're using GoogleCrap� please read this GoogleGroupsPython - Python Wiki.

Mark Lawrence

This one to the list - sorry Mark used the wrong reply button.

I don't work on Python 3 yet but I am trying to get Phoenix to work with matplotlib.

Made a few changes to backend_wx:

Following don't exist in Phoenix (build r73823) - will research later if they should exist.
         #wx.WXK_PRIOR : 'pageup',
         #wx.WXK_NEXT : 'pagedown',
         #wx.WXK_NUMPAD_PRIOR : 'pageup',
         #wx.WXK_NUMPAD_NEXT : 'pagedown',

There are a few EmptyBitMap creates which need to be changed to:

         if 'phoenix' in wx.PlatformInfo:
             self.bitmap = wx.Bitmap(w, h)
         else:
             self.bitmap = wx.EmptyBitmap(w, h)

But now I am stuck on the following exception and I haven't found a solution to this yet - any pointers would be very welcome.

Werner

AttributeError: 'BaseApp' object has no attribute 'ProcessIdle'
File "c:\dev\twcbv4\twcbsrc\controllers\app_stats.py", line 864, in <module>
   apprb = Appstats(None, standalone=True)
File "c:\dev\twcbv4\twcbsrc\controllers\app_stats.py", line 203, in __init__
   self.setupControls()
File "c:\dev\twcbv4\twcbsrc\controllers\app_stats.py", line 236, in setupControls
   self.createStatsPanes()
File "c:\dev\twcbv4\twcbsrc\controllers\app_stats.py", line 401, in createStatsPanes
   self.paneStatsDtypeCons.axes = self.paneStatsDtypeCons.figure.add_subplot(noRow, noCol, 1)
File "c:\Python27\Lib\site-packages\matplotlib\figure.py", line 882, in add_subplot
   a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "c:\Python27\Lib\site-packages\matplotlib\axes.py", line 8938, in __init__
   self._axes_class.__init__(self, fig, self.figbox, **kwargs)
File "c:\Python27\Lib\site-packages\matplotlib\axes.py", line 461, in __init__
   self._init_axis()
File "c:\Python27\Lib\site-packages\matplotlib\axes.py", line 523, in _init_axis
   self.spines['right'].register_axis(self.yaxis)
File "c:\Python27\Lib\site-packages\matplotlib\spines.py", line 151, in register_axis
   self.axis.cla()
File "c:\Python27\Lib\site-packages\matplotlib\axis.py", line 732, in cla
   self.reset_ticks()
File "c:\Python27\Lib\site-packages\matplotlib\axis.py", line 746, in reset_ticks
   self.minorTicks.extend([self._get_tick(major=False)])
File "c:\Python27\Lib\site-packages\matplotlib\axis.py", line 1839, in _get_tick
   return YTick(self.axes, 0, '', major=major, **tick_kw)
File "c:\Python27\Lib\site-packages\matplotlib\axis.py", line 140, in __init__
   self.tick2line = self._get_tick2line()
File "c:\Python27\Lib\site-packages\matplotlib\axis.py", line 541, in _get_tick2line
   l.set_transform(self.axes.get_yaxis_transform(which='tick2'))
File "c:\Python27\Lib\site-packages\matplotlib\lines.py", line 476, in set_transform
   Artist.set_transform(self, t)
File "c:\Python27\Lib\site-packages\matplotlib\artist.py", line 235, in set_transform
   self.pchanged()
File "c:\Python27\Lib\site-packages\matplotlib\artist.py", line 216, in pchanged
   for oid, func in self._propobservers.iteritems():

···

On 19/04/2013 12:26, Mark Lawrence wrote:

On 19/04/2013 04:03, John Ladasky wrote:

Reading more, I realize that the way I was getting GUI output previously
(with Python 2.7 and Matplotlib 1.1) was through wxPython.
Unfortunately, it appears that wxPython's star is fading, and a Python
3-compatible version will not be written. In fact, wxPython hasn't
released a new version in nine months.

I'm surprised that you say this as months of work have gone into
updating wxPython to make in Python 3 compatible. Please see
Index of /Phoenix/snapshot-builds for the latest and greatest.

That’s great news. Unfortunately, I’m not aware of any testing with
it and matplotlib on Python 3, so for someone who just wants to get
things to work, I would still recommend Tk, gtk or Qt4 on Python3.
Mike

···

On 04/19/2013 01:59 AM, C M wrote:

    On Thu, Apr 18, 2013 at 11:03 PM, John

Ladasky <john_ladasky@…209…>
wrote:

.

      Reading more, I realize that the way I was getting GUI output

previously

      (with Python 2.7 and Matplotlib 1.1) was through wxPython.

      Unfortunately, it appears that wxPython's star is fading, and

a Python

      3-compatible version will not be written.  In fact, wxPython

hasn’t

      released a new version in nine months.
      wxPython is alive and well and the newest developmental

version of it (“Phoenix”) runs on Python 3. It should be
released fairly soon. One of the wxPython list regulars
mentioned getting his software to run with it, with a few
minor issues, just six days ago. So you might want to give
Phoenix a try.

Well, that is good news. Just before my last message to this list, I visited wxpython.org, as I have done many times over the years. I saw no announcement that there would be a Python 3.x-compatible version. You would think that the developers would want everyone to know!

···

On 04/19/2013 03:26 AM, Mark Lawrence wrote:

On 19/04/2013 04:03, John Ladasky wrote:

Reading more, I realize that the way I was getting GUI output previously
(with Python 2.7 and Matplotlib 1.1) was through wxPython.
Unfortunately, it appears that wxPython's star is fading, and a Python
3-compatible version will not be written. In fact, wxPython hasn't
released a new version in nine months.

I'm surprised that you say this as months of work have gone into
updating wxPython to make in Python 3 compatible. Please see
Index of /Phoenix/snapshot-builds for the latest and greatest.

Dear all,

I have a set of wave directions in lon lat, but I want to display them in a UTM type projection. I believe the directions will be distorted, but I'm not sure by how much.

Does anyone know of a method for calculating new directions under a projection change?

Thanks again for your help,

Mat

···


Dr. Mathew Topper
Institute for Energy Systems
School of Engineering
The University of Edinburgh
Faraday Building
The King’s Buildings
Edinburgh EH9 3JL
Tel: +44 (0)131 650 5570
School fax: +44 (0)131 650 6554
mathew.topper@…3926… <mailto:mathew.topper@…3926…>
http://www.see.ed.ac.uk/>

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

Hi Mat,

I have a set of wave directions in lon lat,

Not clear how a direction is given as a lon lat. Do you mean you have a set of vectors, each defined as lon/lat pairs?

but I want to display them
in a UTM type projection. I believe the directions will be distorted,
but I'm not sure by how much.

It depends on what you want - if you want the arrow to point where the wind would go after X minutes, then you want the "distortion". If you want the viewer to be able to pick off the geographic heading by eye, then simply convert your lon lat pairs to heading/length pairs and plot them in the axis frame. See http://matplotlib.org/basemap/users/mapcoords.html for how to convert from basemap to the underlying axis frame.

In an ideal world your projection would not be over such a large area that any of this matters - if your vector is off by 1 degree, who will be able to tell in a plot?

Cheers, Jody

···

On Apr 26, 2013, at 3:03 AM, Mathew Topper <mathew.topper@...3926...> wrote:

--
Jody Klymak

Hi Jody,

Thanks for getting in touch. My reply in line also:

My usage is to examine boundary conditions for a spectral wave

model. Thus, I have data points at locations given ingeographic
coordinates with bearings to describe the wave directions.
To clarify, the wave model I am using demands wave directions in the
projection of the grid which is being used, and I am trying to
figure out if I need to change the inputs to the wave model, using
basemap as an indicator, potentially a pre-processor. In fact, I’m having a bit of a intellectual crisis trying to
understand what an instantaneous wave direction is and whether such
a thing should be effected by the projection it is in!
In the plots and also in the model, I think it will make very little
difference to the outputs. However, I am very interested in
quantification of uncertainty and therefore I want to demonstrate
that it could (should the directions need adjustment) make a
difference to the results, particularly if you were a bit slack with
your choice of grid projection.
Thanks again for your help and I’m sorry if this is a little “off
topic”, but I know basemap users are a smart bunch to consult with.
:slight_smile:
All the best,
Mat

···

On 26/04/13 18:34, Jody Klymak wrote:

  Not clear how a direction is given as a lon lat. Do you mean you

have a set of vectors, each defined as lon/lat pairs?

  It depends on what you want - if you want the arrow to point where

the wind would go after X minutes, then you want the “distortion”.
If you want the viewer to be able to pick off the geographic
heading by eye, then simply convert your lon lat pairs to
heading/length pairs and plot them in the axis frame. See
for how to
convert from basemap to the underlying axis frame.

  In an ideal world your projection would not be over

such a large area that any of this matters - if your vector is off
by 1 degree, who will be able to tell in a plot?


Dr. Mathew Topper

  Institute for Energy Systems

  School of Engineering

  The University of Edinburgh

  Faraday Building

  The King’s Buildings

  Edinburgh EH9 3JL

  Tel: +44 (0)131 650 5570

  School fax: +44 (0)131 650 6554

  mathew.topper@...3926...

  [http://www.see.ed.ac.uk](http://www.see.ed.ac.uk/)

http://matplotlib.org/basemap/users/mapcoords.html