Re: [Matplotlib-users] Compiling matplotlib against 64 bit python 2.6 on OSX Snow Leopard

2010-05-27 Thread Friedrich Romstedt
2010/5/25 Pim Schellart :
> I tried both and although it now seems to find the libraries it still
> fails to link something.
>
> src/_png.cpp:293: error: ‘png_infopp_NULL’ was not declared in this scope
> src/_png.cpp:293: error: ‘png_infopp_NULL’ was not declared in this scope

I compiled matplotlib-0.99.1.2 just yesterday fine on Snow Leopard
from source without being aware of make.osx (with freetype2-2.3.12,
libpng-1.4.1).  The problem I'm citing here, which seems to be
actually also your problem, is due to an API change in linbpng from
1.3 to 1.4.  I soon ago pointed this out on the list but there were no
responses.  One can add #defines for the missing things in
src/_png.cpp to fix it.

I don't know if you would run into some more problems but this one is solvable.

But I also modified setupext.py to find my libraries in /usr/local.

Friedrich

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Compiling matplotlib against 64 bit python 2.6 on OSX Snow Leopard

2010-05-27 Thread Pim Schellart
Dear Friedrich,

sorry for the confusion.
It may very well be that I misinterpreted part of the problem as I am
no expert either.
The problem came to be as follows.
At first I used the binaries for the latest stable releases of Python
2.6 + numpy + matplotlib from the respected websites.
But in order to compile a custom library I needed Python to be compiled 64 bit.
This worked for Python, numpy and scipy but not for matplotlib.
I used to be able to compile matplotlib with a simple "sudo python
setup.py install" but when I tried to do this after the change to 64
bit the build failed with some errors which seemed to me to be related
to freetype not being compiled 64 bit (these errors, which I
unfortunately did not save clearly indicated that the linker could not
find some symbols and when I checked the architecture of the libs it
was i386 only).
I tried to fix this by first compiling freetype 64 bit, and later
libpng as well.
The problem now was that setupext.py did not look in the right
location for my new libpng build.
After I installed pkgtool this was also solved, however now the
reported error occurred.
I also could not use the make.osx script from the latest svn checkout
because of a bug in the fetching of zlib which John fixed.
Finally removing my custom installations of freetype and libpng and
using make.osx to fetch and build them solved the problem.
Oh and somewhere in all this mess I also managed to build it but then
got a malloc error when loading so I tried the removing of i386 but
this did not solve the problem so I changed it back.
I guess the conclusion is that the current svn works, but only with
the make.osx approach.
If I had the time I would try it again on a fresh install to see where
the bug is that prevents setup.py from working with a custom compiled
freetype and libpng but for now I am happy that it finally works :)

Kind regards,

Pim Schellart

2010/5/27 Friedrich Romstedt :
> 2010/5/27 Pim Schellart :
>> thank you for the tip, I'll try and see if the stable release works as
>> well with this adjustment.
>> The problem however was not just in compiling on Snow Leopard, but
>> compiling specifically against a custom compiled 64 bit only version
>> of python.
>> This now works with the make.osx file and the latest svn release,
>> although I agree this is an ugly solution and would prefer the same
>> build system on every OS.
>
> Pim,
>
> I must confess that I'm lost a bit in all this details and all this
> patches ... I hope that I'm not alone with this ... Can you maybe give
> a short summary on the list?
>
> First I don't understand why you compiled a "64 bit only" version of
> your Python.  I.e., what am I missing, when I compile my Python 2.6
> the usual way?  (I also have a 64 bit machine.)
>
> Then, your first error seems to originate from:
>> src/ft2font.h:13:22: error: ft2build.h: No such file or directory
>
> I don't know, but I guess it's due to not finding the correct include
> directory for you self-compiled freetype2?  If it is like this, I
> fixed it in setupext.py (the "darwin" section, not the "darwin_"
> section).  The search path list is empty for "darwin", and I added
> "/usr/local" into it.  Actually I don't remember precisely what the
> error was making me fixing this ... And it's true, I simply ignored
> the "# So I'm pointing to ..." comment in setupext.py ...
>
> Then the next error you reported was clearly related to libpng API
> change, so again nothing with 32/64 bit issues.
>
> So, I don't understand your conclusion that at all you have problems
> due to your 64bit-only built Python?  Sorry, maybe I miss something
> obvious?  I think people have been trusting you that it's a 64bit
> issue, and gave suggestions based on that, but maybe it isn't at all?
> Just a whacky thought!  I simply cannot find an error pointing towards
> this root!  I now went throught it again finally, and I found that
> magically John mentioned his "work for 64bit Python on the make.osx
> file", and then there was some "remove all -arch i386" recommendation,
> but it's all a bit unclear to me ... Sorry, I'm not an expert at all,
> my intention is just to track the problem /not to the false root/
> down.
>
> My explanation is: You downloaded by using make.osx an older version
> of libpng (1.2) and additionally a freetype version in local
> directory, so all the -Is are working respectively.  This solved both
> your freetype problem and your libpng problem.  I need some advice
> what else was solved by make.osx?
>
> Of course this path is good for creating binaries with libpng and
> freetype2 hardlinked, but I don't see the clue for your case.
>
> Friedrich
>

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Compiling matplotlib against 64 bit python 2.6 on OSX Snow Leopard

2010-05-27 Thread Friedrich Romstedt
Dear Pim,

2010/5/27 Pim Schellart :
> At first I used the binaries for the latest stable releases of Python
> 2.6 + numpy + matplotlib from the respected websites.
> But in order to compile a custom library I needed Python to be compiled 64 
> bit.

For me this was the same with PIL ... though I didn't need 64bit for
that.  And I agree, for a new Mac user it's a mess.

> This worked for Python, numpy and scipy but not for matplotlib.
> I used to be able to compile matplotlib with a simple "sudo python
> setup.py install" but when I tried to do this after the change to 64
> bit the build failed with some errors which seemed to me to be related
> to freetype not being compiled 64 bit (these errors, which I
> unfortunately did not save clearly indicated that the linker could not
> find some symbols and when I checked the architecture of the libs it
> was i386 only).
> I tried to fix this by first compiling freetype 64 bit, and later
> libpng as well.
> The problem now was that setupext.py did not look in the right
> location for my new libpng build.
> After I installed pkgtool this was also solved, however now the
> reported error occurred.

And this error was due to the API change.

> I also could not use the make.osx script from the latest svn checkout
> because of a bug in the fetching of zlib which John fixed.
> Finally removing my custom installations of freetype and libpng and
> using make.osx to fetch and build them solved the problem.

> Oh and somewhere in all this mess I also managed to build it but then
> got a malloc error when loading so I tried the removing of i386 but
> this did not solve the problem so I changed it back.

This I don't understand.

> I guess the conclusion is that the current svn works, but only with
> the make.osx approach.

I cannot agree currently.  I can try to do my first contact with svn,
but for the stable release, it works as said before with some tweaking
in setupext.py and src/_png.cpp too.  Also we seem to have quite
similar machines and prerequisites.  The setupext.py tweak may be
omittable by using pkgtool.

So my conclusion is that with using pkgtool and the change in
src/_png.cpp matplotlib should be buildable from sources with
setup.py.

John, shouldn't we finally fix this ugly src/_png.cpp problem?  More
and more people run into problems when using the recent libpng-1.4.
The lines to be added to _png.cpp are:

#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL

Maybe libpng defines some constant to make use of in determining
whether the build is with libpng-1.2 or 1.4.

> If I had the time I would try it again on a fresh install to see where
> the bug is that prevents setup.py from working with a custom compiled
> freetype and libpng but for now I am happy that it finally works :)

I can understand you and I'm facing the same problem.

Friedrich

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib-users Digest, Vol 48, Issue 46

2010-05-27 Thread Alan G Isaac
On 5/27/2010 9:54 AM, Sandy Ydnas wrote:
> it is the my point
> show() can not be used during debuging
>
> but without debug option any tools is usless
> since the main problem in coding is debuging ...

But you have never explained your need here.
You cannot start the mainloop (using ``show``)
and then complain that the mainloop is running!
If you want do debug your script, just use
``savefig`` instead of ``show``.  If that is
not adequate, explain why.

Alan Isaac


--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Clip text in bars

2010-05-27 Thread wrpd_mnd

I'm trying to set up a chart that shows a runtime trace of a single frame.
Most of it is straight forward, however one aspect of it is driving me
crazy. I would like to label the inside of the bar fragments (each represent
a function call with the x-extent being its runtime) with the name of the
task, however I would like the text itself to be fully contained within the
bar itself. I should, in theory, be able to set the clipping box of the text
to be the bounding box of the bar and that should give me the result I want.
Except, I'm not getting that. 

Any ideas?

See the code below:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
ax.set_ylim(0,35)
ax.set_xlim(0,1000)

text0 = ax.text(0,11,'JobName',clip_on=True,clip_box=rect[0].get_bbox())

ax.grid(True)

plt.show()

-- 
View this message in context: 
http://old.nabble.com/Clip-text-in-bars-tp28693489p28693489.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Clip text in bars

2010-05-27 Thread Jae-Joon Lee
The bbox needs to be in a proper coordinate.

from matplotlib.transforms import TransformedBbox
bb = TransformedBbox(rect[0].get_bbox(), ax.transData)

Also, do not use clip_on when clip_box is used. clip_on override
clip_box with ax.bbox.

text0 = ax.text(0,11,'JobName', clip_box=bb)

A complete code is attached.

Regards,

-JJ


import matplotlib.pyplot as plt
from matplotlib.transforms import TransformedBbox

fig = plt.figure()

ax = fig.add_subplot(111)
rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
ax.set_ylim(0,35)
ax.set_xlim(0,1000)

bb = TransformedBbox(rect[0].get_bbox(), ax.transData)

text0 = ax.text(0,11,'JobName', clip_box=bb)

ax.grid(True)

plt.show()



On Thu, May 27, 2010 at 8:41 AM, wrpd_mnd  wrote:
>
> I'm trying to set up a chart that shows a runtime trace of a single frame.
> Most of it is straight forward, however one aspect of it is driving me
> crazy. I would like to label the inside of the bar fragments (each represent
> a function call with the x-extent being its runtime) with the name of the
> task, however I would like the text itself to be fully contained within the
> bar itself. I should, in theory, be able to set the clipping box of the text
> to be the bounding box of the bar and that should give me the result I want.
> Except, I'm not getting that.
>
> Any ideas?
>
> See the code below:
>
> import numpy as np
> import matplotlib.pyplot as plt
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
> ax.set_ylim(0,35)
> ax.set_xlim(0,1000)
>
> text0 = ax.text(0,11,'JobName',clip_on=True,clip_box=rect[0].get_bbox())
>
> ax.grid(True)
>
> plt.show()
>
> --
> View this message in context: 
> http://old.nabble.com/Clip-text-in-bars-tp28693489p28693489.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
> --
>
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Fwd: Clearing A Figure (I Know That This Has Been Posted Before But I Does Not Work For Me)

2010-05-27 Thread Marius 't Hart
What I usually do is to clear the axis (using cla() only) right after 
creating or accessing it (either with figure() or subplot() or similar 
magic):


from pylab import *

fig = figure(num=1)

for example in range(5):
  cla()
  plot(rand(100))
  savefig('test-%d.png'%example)



 Original Message 
Subject: 	[Matplotlib-users] Clearing A Figure (I Know That This Has 
Been Posted Before But I Does Not Work For Me)

Date:   Tue, 25 May 2010 02:08:42 -0700 (PDT)
From:   Thistleryver 
To: matplotlib-users@lists.sourceforge.net



I am attempting to run a lot of tests automatically and generate a graph for
each one.  However, at the moment, the previous graph remains on the figure
and the next plot is drawn over it.

I have read extensively the documentation and I have tried a whole lot of
different commands but to no avail.  In the previous post it said to use
pylab.clf() which is exactly what I've been trying to use.

So far I have used pylab.cla(), pylab.clf() and pylab.close() although I
believe that this only closes an open figure window.  I have no idea why it
is not working now especially since it would appear that my question had
already been answered in both the documentation and the forums.

I am using Python 2.6.4 on Ubuntu Linux.

Here is the relevant code I am using:
pylab.plot(xAxis, TrainingPoints, 'b-')

pylab.plot(xAxis, TestPoints, 'r-')

pylab.xlabel('Epochs')

pylab.ylabel('Sum Squared Error')

pylab.title('Plot of Iris Training Errors')

outfilename = str(int(LEARNING_RATE)) + ".png"
print outfilename
pylab.ylim(ymin=0)
pylab.savefig(outfilename)
pylab.cla()
pylab.clf()

I really hope one of you can spot an error otherwise I am completely stuck.
--
View this message in context: 
http://old.nabble.com/Clearing-A-Figure-%28I-Know-That-This-Has-Been-Posted-Before-But-I-Does-Not-Work-For-Me%29-tp28665976p28665976.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Clip text in bars

2010-05-27 Thread R Potter
Ah, thanks a lot. 


--- On Thu, 5/27/10, Jae-Joon Lee  wrote:

> From: Jae-Joon Lee 
> Subject: Re: [Matplotlib-users] Clip text in bars
> To: "wrpd_mnd" 
> Cc: matplotlib-users@lists.sourceforge.net
> Date: Thursday, May 27, 2010, 9:24 AM
> The bbox needs to be in a proper
> coordinate.
> 
> from matplotlib.transforms import TransformedBbox
> bb = TransformedBbox(rect[0].get_bbox(), ax.transData)
> 
> Also, do not use clip_on when clip_box is used. clip_on
> override
> clip_box with ax.bbox.
> 
> text0 = ax.text(0,11,'JobName', clip_box=bb)
> 
> A complete code is attached.
> 
> Regards,
> 
> -JJ
> 
> 
> import matplotlib.pyplot as plt
> from matplotlib.transforms import TransformedBbox
> 
> fig = plt.figure()
> 
> ax = fig.add_subplot(111)
> rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
> ax.set_ylim(0,35)
> ax.set_xlim(0,1000)
> 
> bb = TransformedBbox(rect[0].get_bbox(), ax.transData)
> 
> text0 = ax.text(0,11,'JobName', clip_box=bb)
> 
> ax.grid(True)
> 
> plt.show()
> 
> 
> 
> On Thu, May 27, 2010 at 8:41 AM, wrpd_mnd 
> wrote:
> >
> > I'm trying to set up a chart that shows a runtime
> trace of a single frame.
> > Most of it is straight forward, however one aspect of
> it is driving me
> > crazy. I would like to label the inside of the bar
> fragments (each represent
> > a function call with the x-extent being its runtime)
> with the name of the
> > task, however I would like the text itself to be fully
> contained within the
> > bar itself. I should, in theory, be able to set the
> clipping box of the text
> > to be the bounding box of the bar and that should give
> me the result I want.
> > Except, I'm not getting that.
> >
> > Any ideas?
> >
> > See the code below:
> >
> > import numpy as np
> > import matplotlib.pyplot as plt
> >
> > fig = plt.figure()
> > ax = fig.add_subplot(111)
> > rect = ax.barh(10, 50, 3, facecolor='green',
> visible=True)
> > ax.set_ylim(0,35)
> > ax.set_xlim(0,1000)
> >
> > text0 =
> ax.text(0,11,'JobName',clip_on=True,clip_box=rect[0].get_bbox())
> >
> > ax.grid(True)
> >
> > plt.show()
> >
> > --
> > View this message in context: 
> > http://old.nabble.com/Clip-text-in-bars-tp28693489p28693489.html
> > Sent from the matplotlib - users mailing list archive
> at Nabble.com.
> >
> >
> >
> --
> >
> > ___
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> 


  


--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Is there a way to link axes of imshow plots?

2010-05-27 Thread Adam Fraser
Suppose I have a figure canvas with 3 plots... 2 are images of the same
dimensions plotted with imshow, and the other is a scatterplot. I'd like to
be able to link the x and y axes of the imshow plots so that when I zoom in
one, the other zooms to the same coordinates, and when I pan in one, the
other pans as well.

I started hacking my way around this by subclassing NavigationToolbar2WxAgg
(shown below)... but there are several problems here.
1) This will link the axes of all plots in a canvas since all I've done is
get rid of the checks for a.in_axes()
2) This worked well for panning, but zooming caused all subplots to zoom
from the same global point, rather than from the same point in each of their
respective axes.

Can anyone suggest a workaround?

Much thanks!
-Adam

from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as
NavigationToolbar
class MyNavToolbar(NavigationToolbar):
def __init__(self, canvas, cpfig):
NavigationToolbar.__init__(self, canvas)

# override
def press_pan(self, event):
'the press mouse button in pan/zoom mode callback'

if event.button == 1:
self._button_pressed=1
elif  event.button == 3:
self._button_pressed=3
else:
self._button_pressed=None
return

x, y = event.x, event.y

# push the current view to define home if stack is empty
if self._views.empty(): self.push_current()

self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()):
*# only difference from overridden method is that this one
doesn't*
*# check a.in_axes(event) *
if x is not None and y is not None and a.get_navigate():
a.start_pan(x, y, event.button)
self._xypress.append((a, i))
self.canvas.mpl_disconnect(self._idDrag)
self._idDrag=self.canvas.mpl_connect('motion_notify_event',
self.drag_pan)

def press_zoom(self, event):
'the press mouse button in zoom to rect mode callback'
if event.button == 1:
self._button_pressed=1
elif  event.button == 3:
self._button_pressed=3
else:
self._button_pressed=None
return

x, y = event.x, event.y

# push the current view to define home if stack is empty
if self._views.empty(): self.push_current()

self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()):
*# only difference from overridden method is that this one
doesn't*
*# check a.in_axes(event) *
if x is not None and y is not None and a.get_navigate() and
a.can_zoom():
self._xypress.append(( x, y, a, i, a.viewLim.frozen(),
a.transData.frozen()))

self.press(event)
--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Is there a way to link axes of imshow plots?

2010-05-27 Thread PHobson
Do the "sharex" and "sharey" kwargs help?
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axes
http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.html
-paul

From: Adam Fraser [mailto:adam.n.fra...@gmail.com]
Sent: Thursday, May 27, 2010 10:44 AM
To: matplotlib-users
Subject: [Matplotlib-users] Is there a way to link axes of imshow plots?

Suppose I have a figure canvas with 3 plots... 2 are images of the same 
dimensions plotted with imshow, and the other is a scatterplot. I'd like to be 
able to link the x and y axes of the imshow plots so that when I zoom in one, 
the other zooms to the same coordinates, and when I pan in one, the other pans 
as well.

I started hacking my way around this by subclassing NavigationToolbar2WxAgg 
(shown below)... but there are several problems here.
1) This will link the axes of all plots in a canvas since all I've done is get 
rid of the checks for a.in_axes()
2) This worked well for panning, but zooming caused all subplots to zoom from 
the same global point, rather than from the same point in each of their 
respective axes.

Can anyone suggest a workaround?

Much thanks!
-Adam

from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as 
NavigationToolbar
class MyNavToolbar(NavigationToolbar):
def __init__(self, canvas, cpfig):
NavigationToolbar.__init__(self, canvas)

# override
def press_pan(self, event):
'the press mouse button in pan/zoom mode callback'

if event.button == 1:
self._button_pressed=1
elif  event.button == 3:
self._button_pressed=3
else:
self._button_pressed=None
return

x, y = event.x, event.y

# push the current view to define home if stack is empty
if self._views.empty(): self.push_current()

self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()):
# only difference from overridden method is that this one doesn't
# check a.in_axes(event)
if x is not None and y is not None and a.get_navigate():
a.start_pan(x, y, event.button)
self._xypress.append((a, i))
self.canvas.mpl_disconnect(self._idDrag)
self._idDrag=self.canvas.mpl_connect('motion_notify_event', 
self.drag_pan)

def press_zoom(self, event):
'the press mouse button in zoom to rect mode callback'
if event.button == 1:
self._button_pressed=1
elif  event.button == 3:
self._button_pressed=3
else:
self._button_pressed=None
return

x, y = event.x, event.y

# push the current view to define home if stack is empty
if self._views.empty(): self.push_current()

self._xypress=[]
for i, a in enumerate(self.canvas.figure.get_axes()):
# only difference from overridden method is that this one doesn't
# check a.in_axes(event)
if x is not None and y is not None and a.get_navigate() and 
a.can_zoom():
self._xypress.append(( x, y, a, i, a.viewLim.frozen(), 
a.transData.frozen()))

self.press(event)



--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Is there a way to link axes of imshow plots?

2010-05-27 Thread Jae-Joon Lee
ax1 = subplot(121)
ax2 = subplot(122, sharex=ax1, sharey=ax1)

ax1.set_adjustable("box-forced")
ax2.set_adjustable("box-forced")

arr1 = np.arange(100).reshape((10, 10))
ax1.imshow(arr1)

arr2 = np.arange(100, 0, -1).reshape((10, 10))
ax2.imshow(arr2)

Note the use of set_adjustable("box-forced").
sharex and sharey does not get along with axes of aspect=1 & adjustable="box".

-JJ



On Thu, May 27, 2010 at 2:10 PM,   wrote:
> Do the “sharex” and “sharey” kwargs help?
>
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axes
>
> http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.html
>
> -paul
>
>
>
> From: Adam Fraser [mailto:adam.n.fra...@gmail.com]
> Sent: Thursday, May 27, 2010 10:44 AM
> To: matplotlib-users
> Subject: [Matplotlib-users] Is there a way to link axes of imshow plots?
>
>
>
> Suppose I have a figure canvas with 3 plots... 2 are images of the same
> dimensions plotted with imshow, and the other is a scatterplot. I'd like to
> be able to link the x and y axes of the imshow plots so that when I zoom in
> one, the other zooms to the same coordinates, and when I pan in one, the
> other pans as well.
>
>
>
> I started hacking my way around this by subclassing NavigationToolbar2WxAgg
> (shown below)... but there are several problems here.
>
> 1) This will link the axes of all plots in a canvas since all I've done is
> get rid of the checks for a.in_axes()
>
> 2) This worked well for panning, but zooming caused all subplots to zoom
> from the same global point, rather than from the same point in each of their
> respective axes.
>
>
>
> Can anyone suggest a workaround?
>
>
>
> Much thanks!
>
> -Adam
>
>
>
> from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as
> NavigationToolbar
>
> class MyNavToolbar(NavigationToolbar):
>
>     def __init__(self, canvas, cpfig):
>
>         NavigationToolbar.__init__(self, canvas)
>
>
>
>     # override
>
>     def press_pan(self, event):
>
>         'the press mouse button in pan/zoom mode callback'
>
>
>
>         if event.button == 1:
>
>             self._button_pressed=1
>
>         elif  event.button == 3:
>
>             self._button_pressed=3
>
>         else:
>
>             self._button_pressed=None
>
>             return
>
>
>
>         x, y = event.x, event.y
>
>
>
>         # push the current view to define home if stack is empty
>
>         if self._views.empty(): self.push_current()
>
>
>
>         self._xypress=[]
>
>         for i, a in enumerate(self.canvas.figure.get_axes()):
>
>             # only difference from overridden method is that this one
> doesn't
>
>             # check a.in_axes(event)
>
>             if x is not None and y is not None and a.get_navigate():
>
>                 a.start_pan(x, y, event.button)
>
>                 self._xypress.append((a, i))
>
>                 self.canvas.mpl_disconnect(self._idDrag)
>
>                 self._idDrag=self.canvas.mpl_connect('motion_notify_event',
> self.drag_pan)
>
>
>
>     def press_zoom(self, event):
>
>         'the press mouse button in zoom to rect mode callback'
>
>         if event.button == 1:
>
>             self._button_pressed=1
>
>         elif  event.button == 3:
>
>             self._button_pressed=3
>
>         else:
>
>             self._button_pressed=None
>
>             return
>
>
>
>         x, y = event.x, event.y
>
>
>
>         # push the current view to define home if stack is empty
>
>         if self._views.empty(): self.push_current()
>
>
>
>         self._xypress=[]
>
>         for i, a in enumerate(self.canvas.figure.get_axes()):
>
>             # only difference from overridden method is that this one
> doesn't
>
>             # check a.in_axes(event)
>
>             if x is not None and y is not None and a.get_navigate() and
> a.can_zoom():
>
>                 self._xypress.append(( x, y, a, i, a.viewLim.frozen(),
> a.transData.frozen()))
>
>
>
>         self.press(event)
>
>
>
>
>
>
>
> --
>
>
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] interpolation and colormaps, over and under colors

2010-05-27 Thread T J
Hi,

I am plotting with imshow() and interpolation is turned on
('gaussian').  Part of my issue is that the distribution of values is
such that I need to set the over/under colors to grab the most
relevant values.  If I set the over color to be the "maximum" color,
then the result is too dark.  Conversely for the under color.  I can
set the over/under colors to not draw, but then I have "holes" in my
image.  Is it possible to incorporate interpolation?  That is, I would
like to set my over color to be interpolated among its neighboring
cells.  This seems like it would require an (more) "intelligent"
colormap, so my guess is that this isn't currently supported.  I'm
growing more comfortable with the mpl internals and might give a stab
at implementing this, but I'm not quite sure where to start.

Thanks in advance.

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Is there a way to link axes of imshow plots?

2010-05-27 Thread Adam Fraser
Thanks very much,

I'm getting ValueError: argument must be "box", or "datalim" at
set_adjustable...

I'm using Matplotlib version 0.98.5.3, do I need to update?


On Thu, May 27, 2010 at 2:59 PM, Jae-Joon Lee  wrote:

> ax1 = subplot(121)
> ax2 = subplot(122, sharex=ax1, sharey=ax1)
>
> ax1.set_adjustable("box-forced")
> ax2.set_adjustable("box-forced")
>
> arr1 = np.arange(100).reshape((10, 10))
> ax1.imshow(arr1)
>
> arr2 = np.arange(100, 0, -1).reshape((10, 10))
> ax2.imshow(arr2)
>
> Note the use of set_adjustable("box-forced").
> sharex and sharey does not get along with axes of aspect=1 &
> adjustable="box".
>
> -JJ
>
>
>
> On Thu, May 27, 2010 at 2:10 PM,   wrote:
> > Do the “sharex” and “sharey” kwargs help?
> >
> >
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axes
> >
> >
> http://matplotlib.sourceforge.net/examples/pylab_examples/shared_axis_demo.html
> >
> > -paul
> >
> >
> >
> > From: Adam Fraser [mailto:adam.n.fra...@gmail.com]
> > Sent: Thursday, May 27, 2010 10:44 AM
> > To: matplotlib-users
> > Subject: [Matplotlib-users] Is there a way to link axes of imshow plots?
> >
> >
> >
> > Suppose I have a figure canvas with 3 plots... 2 are images of the same
> > dimensions plotted with imshow, and the other is a scatterplot. I'd like
> to
> > be able to link the x and y axes of the imshow plots so that when I zoom
> in
> > one, the other zooms to the same coordinates, and when I pan in one, the
> > other pans as well.
> >
> >
> >
> > I started hacking my way around this by
> subclassing NavigationToolbar2WxAgg
> > (shown below)... but there are several problems here.
> >
> > 1) This will link the axes of all plots in a canvas since all I've done
> is
> > get rid of the checks for a.in_axes()
> >
> > 2) This worked well for panning, but zooming caused all subplots to zoom
> > from the same global point, rather than from the same point in each of
> their
> > respective axes.
> >
> >
> >
> > Can anyone suggest a workaround?
> >
> >
> >
> > Much thanks!
> >
> > -Adam
> >
> >
> >
> > from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as
> > NavigationToolbar
> >
> > class MyNavToolbar(NavigationToolbar):
> >
> > def __init__(self, canvas, cpfig):
> >
> > NavigationToolbar.__init__(self, canvas)
> >
> >
> >
> > # override
> >
> > def press_pan(self, event):
> >
> > 'the press mouse button in pan/zoom mode callback'
> >
> >
> >
> > if event.button == 1:
> >
> > self._button_pressed=1
> >
> > elif  event.button == 3:
> >
> > self._button_pressed=3
> >
> > else:
> >
> > self._button_pressed=None
> >
> > return
> >
> >
> >
> > x, y = event.x, event.y
> >
> >
> >
> > # push the current view to define home if stack is empty
> >
> > if self._views.empty(): self.push_current()
> >
> >
> >
> > self._xypress=[]
> >
> > for i, a in enumerate(self.canvas.figure.get_axes()):
> >
> > # only difference from overridden method is that this one
> > doesn't
> >
> > # check a.in_axes(event)
> >
> > if x is not None and y is not None and a.get_navigate():
> >
> > a.start_pan(x, y, event.button)
> >
> > self._xypress.append((a, i))
> >
> > self.canvas.mpl_disconnect(self._idDrag)
> >
> >
>  self._idDrag=self.canvas.mpl_connect('motion_notify_event',
> > self.drag_pan)
> >
> >
> >
> > def press_zoom(self, event):
> >
> > 'the press mouse button in zoom to rect mode callback'
> >
> > if event.button == 1:
> >
> > self._button_pressed=1
> >
> > elif  event.button == 3:
> >
> > self._button_pressed=3
> >
> > else:
> >
> > self._button_pressed=None
> >
> > return
> >
> >
> >
> > x, y = event.x, event.y
> >
> >
> >
> > # push the current view to define home if stack is empty
> >
> > if self._views.empty(): self.push_current()
> >
> >
> >
> > self._xypress=[]
> >
> > for i, a in enumerate(self.canvas.figure.get_axes()):
> >
> > # only difference from overridden method is that this one
> > doesn't
> >
> > # check a.in_axes(event)
> >
> > if x is not None and y is not None and a.get_navigate() and
> > a.can_zoom():
> >
> > self._xypress.append(( x, y, a, i, a.viewLim.frozen(),
> > a.transData.frozen()))
> >
> >
> >
> > self.press(event)
> >
> >
> >
> >
> >
> >
> >
> >
> --
> >
> >
> > ___
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
>
--

___
Ma

Re: [Matplotlib-users] Is there a way to link axes of imshow plots?

2010-05-27 Thread Eric Firing
On 05/27/2010 09:08 AM, Adam Fraser wrote:
> Thanks very much,
>
> I'm getting ValueError: argument must be "box", or "datalim" at
> set_adjustable...
>
> I'm using Matplotlib version 0.98.5.3, do I need to update?
>

Yes.  Unfortunately, you will need to build from svn.  JJ added 
box-forced in January, and we have not had a release since then.

Eric

>
> On Thu, May 27, 2010 at 2:59 PM, Jae-Joon Lee  > wrote:
>
> ax1 = subplot(121)
> ax2 = subplot(122, sharex=ax1, sharey=ax1)
>
> ax1.set_adjustable("box-forced")
> ax2.set_adjustable("box-forced")
>
> arr1 = np.arange(100).reshape((10, 10))
> ax1.imshow(arr1)
>
> arr2 = np.arange(100, 0, -1).reshape((10, 10))
> ax2.imshow(arr2)
>
> Note the use of set_adjustable("box-forced").
> sharex and sharey does not get along with axes of aspect=1 &
> adjustable="box".
>
> -JJ

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] interpolation and colormaps, over and under colors

2010-05-27 Thread Eric Firing
On 05/27/2010 09:32 AM, T J wrote:
> Hi,
>
> I am plotting with imshow() and interpolation is turned on
> ('gaussian').  Part of my issue is that the distribution of values is
> such that I need to set the over/under colors to grab the most
> relevant values.  If I set the over color to be the "maximum" color,
> then the result is too dark.  Conversely for the under color.  I can
> set the over/under colors to not draw, but then I have "holes" in my
> image.  Is it possible to incorporate interpolation?  That is, I would
> like to set my over color to be interpolated among its neighboring
> cells.  This seems like it would require an (more) "intelligent"
> colormap, so my guess is that this isn't currently supported.  I'm
> growing more comfortable with the mpl internals and might give a stab
> at implementing this, but I'm not quite sure where to start.
>
> Thanks in advance.


I'm not sure I understand the problem; could you provide a tiny example 
to illustrate?

Eric

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] interpolation and colormaps, over and under colors

2010-05-27 Thread T J
On Thu, May 27, 2010 at 3:23 PM, Eric Firing  wrote:
>
> I'm not sure I understand the problem; could you provide a tiny example
> to illustrate?
>

Sure, let me focus just on the interpolation and I'll leave the
filtering issue out.

In the script below, I plot a 3x3 array with the center element having
an "over" value.  In the default case, because its value is over, the
colormap will assign it the maximum color.  I also plot the case when
the "over" color is explicitly set to the minimum color and also to
white.  What I want is this:

   The center element should be an equal mixture of the 4 elements around it.

This is partially achieved with "white" (and I suppose I could pick
"grey" or "black"), but I think it might be nicer if it were a pure
mixture, rather than a mixture of the surrounding colors and the
"over" color.

The script is attached below.  Sorry it is a bit long, but I needed a
discrete colormap.  Can we get cmap_discrete() into matplotlib?

--

import matplotlib.pyplot as plt
import matplotlib.colors

import numpy as np
from scipy import interpolate

 http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
 Can this be added to matplotlib?
def cmap_discretize(cmap, N):
"""Return a discrete colormap from the continuous colormap cmap.

cmap: colormap instance, eg. cm.jet.
N: Number of colors.

Example
x = resize(arange(100), (5,100))
djet = cmap_discretize(cm.jet, 5)
imshow(x, cmap=djet)
"""

cdict = cmap._segmentdata.copy()
# N colors
colors_i = np.linspace(0,1.,N)
# N+1 indices
indices = np.linspace(0,1.,N+1)
for key in ('red','green','blue'):
# Find the N colors
D = np.array(cdict[key])
I = interpolate.interp1d(D[:,0], D[:,1])
colors = I(colors_i)
# Place these colors at the correct indices.
A = np.zeros((N+1,3), float)
A[:,0] = indices
A[1:,1] = colors
A[:-1,2] = colors
# Create a tuple for the dictionary.
L = []
for l in A:
L.append(tuple(l))
cdict[key] = tuple(L)
# Return colormap object.
return matplotlib.colors.LinearSegmentedColormap('colormap',cdict,1024)

def draw(m, cm, norm, ncolors):
ax = plt.gca()
ai = ax.imshow(m, cmap=cm, norm=norm, interpolation='gaussian')
cb = ax.figure.colorbar(ai)
cb.set_ticks(np.linspace(.5, ncolors-.5, ncolors))
cb.set_ticklabels(['$%s$' % (i,) for i in np.arange(ncolors)])
return ai, cb

if __name__ == '__main__':
ncolors = 4
norm = plt.Normalize(vmax=ncolors)
m = np.array([[0,  0, 1],
  [3, 10, 1],
  [3,  2, 2]])

for over in [None, 'min', (1,1,1,1)]:
f = plt.figure()
cm = cmap_discretize(plt.cm.jet, ncolors)
if over == 'min':
cm.set_over(cm(0.0))
elif over is not None:
cm.set_over(over)
ai, cb = draw(m, cm, norm, ncolors)

plt.show()

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] interpolation and colormaps, over and under colors

2010-05-27 Thread Eric Firing
On 05/27/2010 01:58 PM, T J wrote:
> On Thu, May 27, 2010 at 3:23 PM, Eric Firing  wrote:
>>
>> I'm not sure I understand the problem; could you provide a tiny example
>> to illustrate?
>>
>
> Sure, let me focus just on the interpolation and I'll leave the
> filtering issue out.
>
> In the script below, I plot a 3x3 array with the center element having
> an "over" value.  In the default case, because its value is over, the
> colormap will assign it the maximum color.  I also plot the case when
> the "over" color is explicitly set to the minimum color and also to
> white.  What I want is this:
>
> The center element should be an equal mixture of the 4 elements around it.

You can't do this via any manipulation of the colormap, or any fancier 
colormap specification--instead, you have to manipulate the data value. 
  For example, you could identify the "over" values in your data, and 
then use 2-D interpolation to replace them with the values you want.

Basemap includes a 2-D interpolation routine:

from mpl_toolkits.basemap import interp

>
> This is partially achieved with "white" (and I suppose I could pick
> "grey" or "black"), but I think it might be nicer if it were a pure
> mixture, rather than a mixture of the surrounding colors and the
> "over" color.
>
> The script is attached below.  Sorry it is a bit long, but I needed a
> discrete colormap.  Can we get cmap_discrete() into matplotlib?

No, because it doesn't make much sense, given the mpl paradigm in which 
a colormap and a norm work together.  If you want 4 colors, make a 
colormap with 4 colors, and use a norm that maps your data to those 4 
colors.

For example:

cm4 = get_cmap('jet', 4)
cm4a = mpl.colors.ListedColormap(get_cmap('jet', 256)([20, 70, 150, 200]))

You can select any discrete set of colors you want using ListedColormap.

Then you can use the default Normalize, or a custom BoundaryNorm, to map 
data ranges to the colors.  You just don't need a lookup table with 1024 
entries to specify 4 colors--it doesn't gain you anything.

Eric



>
> --
>
> import matplotlib.pyplot as plt
> import matplotlib.colors
>
> import numpy as np
> from scipy import interpolate
>
>  http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
>  Can this be added to matplotlib?
> def cmap_discretize(cmap, N):
>  """Return a discrete colormap from the continuous colormap cmap.
>
>  cmap: colormap instance, eg. cm.jet.
>  N: Number of colors.
>
>  Example
>  x = resize(arange(100), (5,100))
>  djet = cmap_discretize(cm.jet, 5)
>  imshow(x, cmap=djet)
>  """
>
>  cdict = cmap._segmentdata.copy()
>  # N colors
>  colors_i = np.linspace(0,1.,N)
>  # N+1 indices
>  indices = np.linspace(0,1.,N+1)
>  for key in ('red','green','blue'):
>  # Find the N colors
>  D = np.array(cdict[key])
>  I = interpolate.interp1d(D[:,0], D[:,1])
>  colors = I(colors_i)
>  # Place these colors at the correct indices.
>  A = np.zeros((N+1,3), float)
>  A[:,0] = indices
>  A[1:,1] = colors
>  A[:-1,2] = colors
>  # Create a tuple for the dictionary.
>  L = []
>  for l in A:
>  L.append(tuple(l))
>  cdict[key] = tuple(L)
>  # Return colormap object.
>  return matplotlib.colors.LinearSegmentedColormap('colormap',cdict,1024)
>
> def draw(m, cm, norm, ncolors):
>  ax = plt.gca()
>  ai = ax.imshow(m, cmap=cm, norm=norm, interpolation='gaussian')
>  cb = ax.figure.colorbar(ai)
>  cb.set_ticks(np.linspace(.5, ncolors-.5, ncolors))
>  cb.set_ticklabels(['$%s$' % (i,) for i in np.arange(ncolors)])
>  return ai, cb
>
> if __name__ == '__main__':
>  ncolors = 4
>  norm = plt.Normalize(vmax=ncolors)
>  m = np.array([[0,  0, 1],
>[3, 10, 1],
>[3,  2, 2]])
>
>  for over in [None, 'min', (1,1,1,1)]:
>  f = plt.figure()
>  cm = cmap_discretize(plt.cm.jet, ncolors)
>  if over == 'min':
>  cm.set_over(cm(0.0))
>  elif over is not None:
>  cm.set_over(over)
>  ai, cb = draw(m, cm, norm, ncolors)
>
>  plt.show()


--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users