Re: [Matplotlib-users] Nasty mouse event problem with wxPython

2010-05-07 Thread Matt Newville
Hi Soren,

2010/5/6 Søren Nielsen :
> Thanks Matt,
>
> The wx.ReleaseMouse() event when called before the wx.MessageBox also works
> great.
>
> I have a similar problem when I want to make a popup menu after the user has
> clicked on a patch (through the pick event) .. it works on Windows but the
> popup menu doesn't show on Linux (or only shows in rare occasions) . A
> wx.ReleaseMouse() doesn't seem to work here.. I've made a sample script that
> shows the problem. It doesn't use the pick event, but the same problem
> applies when using the button_press_event. If I want to go through the pick
> event then of course the button_release_event workaround doesn't work
> either.
>
> Also, clicking the right and left button like crazy to make the popup menu
> show on linux can result in the error:
>
> Traceback (most recent call last):
>   File
> "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_wx.py", line
> 1218, in _onKeyDown
>     FigureCanvasBase.key_press_event(self, key, guiEvent=evt)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py",
> line 1142, in key_press_event
>     event = KeyEvent(s, self, key, self._lastx, self._lasty,
> guiEvent=guiEvent)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py",
> line 970, in __init__
>     LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py",
> line 813, in __init__
>     axes_list = [a for a in self.canvas.figure.get_axes() if
> a.in_axes(self)]
>   File "/usr/lib64/python2.6/site-packages/matplotlib/axes.py", line 1538,
> in in_axes
>     return self.patch.contains(mouseevent)[0]
>   File "/usr/lib64/python2.6/site-packages/matplotlib/patches.py", line 501,
> in contains
>     x, y = self.get_transform().inverted().transform_point(
>   File "/usr/lib64/python2.6/site-packages/matplotlib/patches.py", line 119,
> in get_transform
>     return self.get_patch_transform() + artist.Artist.get_transform(self)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 1033, in __add__
>     return composite_transform_factory(self, other)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 2004, in composite_transform_factory
>     return CompositeAffine2D(a, b)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 1964, in __init__
>     Affine2DBase.__init__(self)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 1304, in __init__
>     Transform.__init__(self)
>   File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 87, in __init__
>     self._parents = WeakKeyDictionary()
>   File "/usr/lib64/python2.6/weakref.py", line 232, in __init__
>     def remove(k, selfref=ref(self)):
> RuntimeError: maximum recursion depth exceeded while calling a Python object

I don't see that error, but perhaps I didn't emulate "click like
crazy" well enough.

I also see that trying to get a Popup Menu on Linux from events
generated by mpl does not reliably display a menu.  In my experience,
a work-around is to replace a direct call to
wx.Popup(menu)
with
wx.CallAfter(wx.Popup, menu)

I don't know if this is related to the problem described earlier, in
which the wx object containing the FigureCanvasWxAgg needs to call
ReleaseMouse() on Linux but not Windows.  As I said earlier, I have
not investigated very thoroughly so am reluctant to jump to any
conclusions about where the problem really lies and what the best
solution is.

An example with a Popup Menu that displays on right- or left-click of
a FigureCanvasWxAgg is below.
Cheers,

--Matt Newville

#!/usr/bin/python
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure

class PlotFrame(wx.Frame):
def __init__(self, title='Plot Frame', **kwds):
wx.Frame.__init__(self, None, -1, title=title, **kwds)
self.panel = wx.Panel(self, -1,size=(600,500))
self.fig = Figure()
self.canvas = FigureCanvasWxAgg(self.panel, -1, self.fig)
self.fig.add_subplot(111)

self.canvas.mpl_connect('button_press_event',
self.onMouseButtonClick)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.LEFT |wx.TOP | wx.GROW)
self.panel.SetSizer(sizer)

self.SetAutoLayout(True)
self.Fit()

def onMouseButtonClick(self, event=None):
if event is None:
return
if event.inaxes:
menu = wx.Menu()
if event.button == 1:
menu.Append(1, 'Left Click: Set as Background file')
self.Bind(wx.EVT_MENU, self.onSelect1)
elif event.button == 3:
menu.Append(1, 'RightClick: Do something else')
self.Bind(wx.EVT_MENU, self.onSelect2)

wx.CallAfter(self.PopupMenu, menu)

def onSelect1(self, 

[Matplotlib-users] Complex layouts of subplots

2010-05-07 Thread Bartosz Telenczuk
Dear all,

I am working on figures for my thesis, which consist of several related panels. 
Each of the panel contains several subplots. In order to arrange the plots I 
would like to split the figure into two (or more) panels and within each of 
them create a nested set of subplots.  Optimally, the main panels should define 
their own coordinate systems, such that all of the nested subplot positions are 
defined within their frame. The syntax could look like that:

panel1 = subplot(1,2,1)
panel2 = subplot(1,2,2)

ax1 = panel1.add_subplot(1,2,1)
ax2 = panel1.add_subplot(1,2,2)

ax3 = panel2.add_subplot(111)

For now it is not possible, because panel1 and panel2 are Axes instances which 
do not have add_subplot method. The only solution I am aware of is to define 
all of the subplots by hand using subplot or axes function with positions 
defined within whole figure coordinate system:

fig = figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,3)
ax3 = fig.add_subplot(1,2,2)


This is of course more difficult, less flexible and requires the user to decide 
in advance on the layout of the panel. 

Until now I exported each figure to SVG file and arranged them in one file 
using SVG directives. I also started implementing my own Multipanel class for 
matplotlib, but it proved out to be not so easy. Therefore I would like to ask 
if someone has implemented a similar approach or could give me some hints on 
the implementation.

I will be very grateful for any help.

Cheers,

Bartek
--

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


[Matplotlib-users] sketch bar?

2010-05-07 Thread oyster
I know matplotlib mimics matlab, which offers scientific look.
but can we use matplotlib to get  a skecth(in other words,
hand-drawing) style for bar/pie/etc in none formalist paper? for
example, http://teethgrinder.co.uk/open-flash-chart/gallery-bar-7.php
thanks

--

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


[Matplotlib-users] what decides which lines go on top of the rest

2010-05-07 Thread Valentino Gonzalez
I am trying to make a scatter plot (it is important that it is a scatter 
plot because I want the markers to be color coded).  Each point also has 
errobars associated and since there is no way to plot errorbars on 
scatter plots I am plotting them separately, i.e. plot twice: once with 
the errorbars and no markers and then with only markers as in a scatter 
plot. 
The problem is that regardless of the order in which I do this, the 
errorbars are alwas on top of the markers of the scatter plot and I 
would like the opposite, markers on top of the errorbars.  Can  this be 
done? And more generally, how can I choose what goes on top of what?


Thanks,
Valentino.-
--

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


Re: [Matplotlib-users] what decides which lines go on top of the rest

2010-05-07 Thread Ryan May
On Wed, May 5, 2010 at 4:36 PM, Valentino Gonzalez  wrote:
> I am trying to make a scatter plot (it is important that it is a scatter
> plot because I want the markers to be color coded).  Each point also has
> errobars associated and since there is no way to plot errorbars on scatter
> plots I am plotting them separately, i.e. plot twice: once with the
> errorbars and no markers and then with only markers as in a scatter plot.
> The problem is that regardless of the order in which I do this, the
> errorbars are alwas on top of the markers of the scatter plot and I would
> like the opposite, markers on top of the errorbars.  Can  this be done? And
> more generally, how can I choose what goes on top of what?

You should be able to pass zorder= to the plotting functions
to control the order.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

--

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


Re: [Matplotlib-users] sketch bar?

2010-05-07 Thread Eric Firing
On 05/06/2010 08:02 PM, oyster wrote:
> I know matplotlib mimics matlab, which offers scientific look.
> but can we use matplotlib to get  a skecth(in other words,
> hand-drawing) style for bar/pie/etc in none formalist paper? for
> example, http://teethgrinder.co.uk/open-flash-chart/gallery-bar-7.php
> thanks

With a considerable effort you could use mpl's capabilities to program 
this sort of thing, but it will not be added as an option.

Eric

--

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


Re: [Matplotlib-users] Complex layouts of subplots

2010-05-07 Thread Friedrich Romstedt
2010/5/7 Bartosz Telenczuk :
> Dear all,
>
> I am working on figures for my thesis, which consist of several related
panels. Each of the panel contains several subplots. In order to arrange the
plots I would like to split the figure into two (or more) panels and within
each of them create a nested set of subplots.  Optimally, the main panels
should define their own coordinate systems, such that all of the nested
subplot positions are defined within their frame. The syntax could look like
that:
>
> panel1 = subplot(1,2,1)
> panel2 = subplot(1,2,2)
>
> ax1 = panel1.add_subplot(1,2,1)
> ax2 = panel1.add_subplot(1,2,2)
>
> ax3 = panel2.add_subplot(111)

I think what you could maybe try is to write a class using figure.add_axes()

http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure.add_axes

The class could store a relative area and a "master".  For the panels you
need, the master would be the Figure.  Such a Panel class could expose an
add_axes() method too, but forwarding the call to its master.  To calculate
the *rect* argument when callings its master's .add_axes(), it would use a
linear transformation from the stored extent to the (0, 1) extent relative
to the master.  Let it be depicted:

+--+  Figure
+-+   Panel
+--+  Axes

There could be more Panels in between.  You would do:

>>> panel = Panel(figure, (0.2, 0.6))  # left = 0.2, width = 0.6, i.e. right
= 0.8
>>> axes = panel.add_axes((0, 0.5))  # left = 0, width = 0.5, i.e. right =
0.5

The last call would do:

1)  Transform the (0, 0.5) to the Figure reference frame (more precise, to
the master ref frame, where by coincidence the Figure is the master).  Thie
yields here (0.2, 0.3) = (left, width), i.e. right = 0.5 (in the master ref
frame).

2)  Call master.add_axes((0.2, 0.3)).  This actually creates the Axes
instance by recusions until the master is a Figure.

I think this approach is feasible in < 200 loc.

hth
Friedrich
--

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


[Matplotlib-users] logarithmic chart (y axis) with dates along x axis?

2010-05-07 Thread fafcb
I'm new to matplotlib, so maybe this is obvious, but I've search quite a bit
and can't find the answer.

I have a data set with several hundred rows and about 5 columns.  I want to
plot all data points (columns 2-5) on the same logarithmic chart with the x
axis showing calendar dates (column 1).

What is the best way to accomplish my task?  I have been experimenting with
semilogy, but I can't seem to figure out how to get columns 2-5 to plot by
date.  Just FYI, if it matters - the data is currently held in a csv file
and each column may or may not have a data point for each date.

Thanks in advance for any help!
--

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