Re: [Matplotlib-users] Get contourf image as array

2014-10-16 Thread David Hoese
Thanks Ben. I'll take a look through the archive.

On 10/16/14, 9:43 AM, Benjamin Root wrote:
> What you are looking for is called "rasterization". Matplotlib does this
> deep within the codebase and is not accessible (believe me, I tried).
> However, there have been other discussions in this mailing list about
> how to use GDAL to rasterize a set of polygons (represented as paths),
> including some links to stack-overflow questions. It isn't a complete
> end-to-end solution, but the pieces are there.
>
> Cheers!
> Ben Root
>
>
> On Wed, Oct 15, 2014 at 2:09 PM, David Hoese  <mailto:dho...@gmail.com>> wrote:
>
> For the first question, if I save the figure (as a PNG I'm guessing,
> unless you can save into a more array-like format), I'd have to make
> sure that there were no labels or ticks and that the axes fit the whole
> figure. I'd also have to get the dpi and size information correct, but I
> suppose it would be possible that way. I was hoping for something a
> little easier and in-memory. This might be the simplest answer the more
> I think about it.
>
> If I'm starting from the paths, I'd still have to write them to the
> "grid" array. I thought maybe the backend could do that and I magically
> get the image.
>
> I'll look in to using savefig and getting the data out.
>
> -Dave
>
> On 10/15/14, 12:42 PM, Joy merwin monteiro wrote:
> > pardon the query if it seems dumb, but why don't you do a savefig()
> > after plotting the data and then convert it to any format you like?
> >
> > alternatively, contour() and contourf() both create paths that can
> > be accessed:
> >
> > cf = contourf(.)
> >
> > output = cf.collections.pop()
> > paths = output.get_paths()[i] # for the various contours
> >
> > the x,y coordinates can then be accessed as
>     >
> > xcoords = paths.vertices.transpose()[0]
> > ycoords = paths.vertices.transpose()[1]
> >
> > you can then do whatever you wish with them.
> >
> > Joy
> >
> >
> > On Wed, Oct 15, 2014 at 9:11 PM, David Hoese  <mailto:dho...@gmail.com>
>  > <mailto:dho...@gmail.com <mailto:dho...@gmail.com>>> wrote:
>  >
>  > I've been searching and reading through source code and
> google searches
>  > to see if this is possible, but no luck so far. I'm basically
> trying to
>  > map some data using Basemap, use contourf to map it to an
> image, and
>  > then put that image in a geotiff (or other format) for use in
> other GIS
>  > programs. I have other tools for remapping data and creating
> geotiffs,
>  > but the contour image looks better. All I would need to get
> this to work
>  > would be an array representing the image inside the axes of a
> contourf
>  > plot. I found a lot of geotiff -> Basemap png results, but I
> would like
>  > the reverse.
>  >
>  > Since the plots are made using paths/patches I'm guessing I
> would have
>  > to have a backend render the image and then extract the image
> somehow.
>  > Does anyone have some tips or tricks to do something like
> this? Or am I
>  > thinking about this completely wrong?
>  >
>  > Thanks for any help and if you could CC me in any replies it
> would be
>  > much appreciated.
>  >
>  > -Dave
>  >
>  >
>   
> --
>  > Comprehensive Server Monitoring with Site24x7.
>  > Monitor 10 servers for $9/Month.
>  > Get alerted through email, SMS, voice calls or mobile push
>  > notifications.
>  > Take corrective actions from your mobile device.
>  > http://p.sf.net/sfu/Zoho
>  > ___
>  > Matplotlib-users mailing list
>  > Matplotlib-users@lists.sourceforge.net
> <mailto:Matplotlib-users@lists.sourceforge.net>
>  > <mailto:Matplotlib-users@lists.sourceforge.net
> <mailto:Matplotlib-users@lists.sourceforge.net>>
>  > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>  >
>  >
>  >
>  >
>  > --
>  > The best ruler, wh

Re: [Matplotlib-users] Get contourf image as array

2014-10-15 Thread David Hoese
For the first question, if I save the figure (as a PNG I'm guessing, 
unless you can save into a more array-like format), I'd have to make 
sure that there were no labels or ticks and that the axes fit the whole 
figure. I'd also have to get the dpi and size information correct, but I 
suppose it would be possible that way. I was hoping for something a 
little easier and in-memory. This might be the simplest answer the more 
I think about it.

If I'm starting from the paths, I'd still have to write them to the 
"grid" array. I thought maybe the backend could do that and I magically 
get the image.

I'll look in to using savefig and getting the data out.

-Dave

On 10/15/14, 12:42 PM, Joy merwin monteiro wrote:
> pardon the query if it seems dumb, but why don't you do a savefig()
> after plotting the data and then convert it to any format you like?
>
> alternatively, contour() and contourf() both create paths that can
> be accessed:
>
> cf = contourf(.)
>
> output = cf.collections.pop()
> paths = output.get_paths()[i] # for the various contours
>
> the x,y coordinates can then be accessed as
>
> xcoords = paths.vertices.transpose()[0]
> ycoords = paths.vertices.transpose()[1]
>
> you can then do whatever you wish with them.
>
> Joy
>
>
> On Wed, Oct 15, 2014 at 9:11 PM, David Hoese  <mailto:dho...@gmail.com>> wrote:
>
> I've been searching and reading through source code and google searches
> to see if this is possible, but no luck so far. I'm basically trying to
> map some data using Basemap, use contourf to map it to an image, and
> then put that image in a geotiff (or other format) for use in other GIS
> programs. I have other tools for remapping data and creating geotiffs,
> but the contour image looks better. All I would need to get this to work
> would be an array representing the image inside the axes of a contourf
> plot. I found a lot of geotiff -> Basemap png results, but I would like
> the reverse.
>
> Since the plots are made using paths/patches I'm guessing I would have
> to have a backend render the image and then extract the image somehow.
> Does anyone have some tips or tricks to do something like this? Or am I
> thinking about this completely wrong?
>
> Thanks for any help and if you could CC me in any replies it would be
> much appreciated.
>
> -Dave
>
> 
> --
> Comprehensive Server Monitoring with Site24x7.
> Monitor 10 servers for $9/Month.
> Get alerted through email, SMS, voice calls or mobile push
> notifications.
> Take corrective actions from your mobile device.
> http://p.sf.net/sfu/Zoho
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> <mailto:Matplotlib-users@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
>
> --
> The best ruler, when he finishes his
> tasks and completes his affairs,
> the people say
> “It all happened naturally”
>
>   - Te Tao Ch'ing

--
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Get contourf image as array

2014-10-15 Thread David Hoese
I've been searching and reading through source code and google searches 
to see if this is possible, but no luck so far. I'm basically trying to 
map some data using Basemap, use contourf to map it to an image, and 
then put that image in a geotiff (or other format) for use in other GIS 
programs. I have other tools for remapping data and creating geotiffs, 
but the contour image looks better. All I would need to get this to work 
would be an array representing the image inside the axes of a contourf 
plot. I found a lot of geotiff -> Basemap png results, but I would like 
the reverse.

Since the plots are made using paths/patches I'm guessing I would have 
to have a backend render the image and then extract the image somehow. 
Does anyone have some tips or tricks to do something like this? Or am I 
thinking about this completely wrong?

Thanks for any help and if you could CC me in any replies it would be 
much appreciated.

-Dave

--
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] real time plotting

2013-03-11 Thread David Hoese
I agree, I don't think that will work with mpl's animation stuff or at 
least I wouldn't want to do it that way. I've created GUIs that received 
data from a weather instrument in real-time. I did method 3 that I 
mentioned before because I knew the scientists using it were going to 
want more and more features.


...I FOUND A WAY FOR YOU TO CHEAT:
You can use the Qt "processEvents()" method to have it process 
drawing/painting operation between the event loop iterations. This 
method is frowned upon when doing real Qt GUIs, but eh go for it. If you 
aren't doing anything more serious than watching the output of your 
processing as it goes then try this:


import matplotlib

matplotlib.use('qt4agg')

import matplotlib as mpl

import matplotlib.pyplot as plt
plt.ion()
import numpy as np
from time import sleep
from PyQt4 import QtGui,QtCore
fig=plt.figure()
plt.axis([0,1000,0,1])

i=0
x=list()
y=list()

while i <1000:
temp_y=np.random.random()
x.append(i)
y.append(temp_y)
plt.scatter(i,temp_y)
i+=1
plt.draw()
sleep(1)
QtGui.qApp.processEvents()

Good luck,
Dave

On 3/11/13 12:59 PM, Neal Becker wrote:
I go through a compute loop that takes maybe a few seconds per pass, 
then plot a new point on the graph.  Do I have to?  No - I thought mpl 
was supposed to do this and wanted to learn how.  If it really doesn't 
work I'll do something else.


I don't think animation is correct here - I had the impression 
animation is where my update would be run as a callback, with a main 
loop that calls me periodically.  Could that fit the model I 
described, where a lengthy computation produces a new value every 
few/10s of seconds?



On Mon, Mar 11, 2013 at 1:55 PM, David Hoese <mailto:dho...@gmail.com>> wrote:


Someone may have to correct me, but I think this has to do with
the Qt4 event loop and it not being run properly. When you get
into real time plotting it can get kind of tricky. In your case (I
got the same results). I have made real-time PyQt4 GUIs before and
have always used separate QThreads and Qt signals/slots to update
the plot. I've never used GTK so I'm not sure why that worked vs
Qt, I would think they would use similar principles but matplotlib
does some magic behind the scenes sometimes. You can see different
results if you comment out the while loop and import the module
into your python/ipython interpreter. After doing this you'll see
the figure pop up (you don't even need the fig.canvas.show() for
this part if interactive mode is on. I went one step further and
turned the while loop into a function:

def one_iter(i):
# Contents of while loop

Calling this in the interpreter shows the figure updating after
each call, but running in a loop (even with sleep) won't show any
updates until the loop is done. In my opinion you have a few
choices that really depend on your programming comfort level:

1. Don't make a real-time plot.
Do you really need a real-time plot that updates from some
external source?
2. Maybe you should look at the matplotlib animation functionality
(http://matplotlib.org/api/animation_api.html). I like this
tutorial:
http://jakevdp.github.com/blog/2012/08/18/matplotlib-animation-tutorial/.
This won't get you a real-time GUI exactly, but it can help if
what you're doing isn't too complicated. It can also be nice for
making videos of plot animations.
3. If you need a GUI with multiple plots and you need for future
feature creep, I would research making PyQt4 GUIs, QThreads, Qt
signals and slots, and putting matplotlib figures into a PyQt4
GUI. This is complex if you are not familiar with GUI programming
and will take a while.

Sorry I couldn't be of more help, but it really depends on what
exactly you are doing.  Mainly, what do you mean by real-time? Do
you really mean animation? Let me know what you come up with, I'm
interested.

-Dave

P.S. Why use a while loop? You can do the same thing with:

for i in range(1000):
# Do stuff


On 3/11/13 10:34 AM, Neal Becker wrote:

I added fig.canvas.show(). It still does nothing.

If I add
mpl.use ('GTK'), now it seems to be doing realtime plotting.

import matplotlib as mpl

import matplotlib.pyplot as plt
plt.ion()
import numpy as np
fig=plt.figure()
plt.axis([0,1000,0,1])

i=0
x=list()
y=list()

fig.canvas.show()
while i <1000:
temp_y=np.random.random()
x.append(i)
y.append(temp_y)
plt.scatter(i,temp_y)
i+=1
plt.draw()



On Mon, Mar 11, 2013 at 10:35 AM, David Hoese mailto:dho...@gmail.com>> wrote:

Oops forgot to change the subject line.

On 

Re: [Matplotlib-users] real time plotting

2013-03-11 Thread David Hoese
Someone may have to correct me, but I think this has to do with the Qt4 
event loop and it not being run properly. When you get into real time 
plotting it can get kind of tricky. In your case (I got the same 
results). I have made real-time PyQt4 GUIs before and have always used 
separate QThreads and Qt signals/slots to update the plot. I've never 
used GTK so I'm not sure why that worked vs Qt, I would think they would 
use similar principles but matplotlib does some magic behind the scenes 
sometimes. You can see different results if you comment out the while 
loop and import the module into your python/ipython interpreter. After 
doing this you'll see the figure pop up (you don't even need the 
fig.canvas.show() for this part if interactive mode is on. I went one 
step further and turned the while loop into a function:


def one_iter(i):
# Contents of while loop

Calling this in the interpreter shows the figure updating after each 
call, but running in a loop (even with sleep) won't show any updates 
until the loop is done. In my opinion you have a few choices that really 
depend on your programming comfort level:


1. Don't make a real-time plot.
Do you really need a real-time plot that updates from some 
external source?
2. Maybe you should look at the matplotlib animation functionality 
(http://matplotlib.org/api/animation_api.html). I like this tutorial: 
http://jakevdp.github.com/blog/2012/08/18/matplotlib-animation-tutorial/. This 
won't get you a real-time GUI exactly, but it can help if what you're 
doing isn't too complicated. It can also be nice for making videos of 
plot animations.
3. If you need a GUI with multiple plots and you need for future feature 
creep, I would research making PyQt4 GUIs, QThreads, Qt signals and 
slots, and putting matplotlib figures into a PyQt4 GUI. This is complex 
if you are not familiar with GUI programming and will take a while.


Sorry I couldn't be of more help, but it really depends on what exactly 
you are doing.  Mainly, what do you mean by real-time? Do you really 
mean animation? Let me know what you come up with, I'm interested.


-Dave

P.S. Why use a while loop? You can do the same thing with:

for i in range(1000):
# Do stuff

On 3/11/13 10:34 AM, Neal Becker wrote:

I added fig.canvas.show(). It still does nothing.

If I add
mpl.use ('GTK'), now it seems to be doing realtime plotting.

import matplotlib as mpl

import matplotlib.pyplot as plt
plt.ion()
import numpy as np
fig=plt.figure()
plt.axis([0,1000,0,1])

i=0
x=list()
y=list()

fig.canvas.show()
while i <1000:
temp_y=np.random.random()
x.append(i)
y.append(temp_y)
plt.scatter(i,temp_y)
i+=1
plt.draw()



On Mon, Mar 11, 2013 at 10:35 AM, David Hoese <mailto:dho...@gmail.com>> wrote:


    Oops forgot to change the subject line.

On 3/11/13 9:34 AM, David Hoese wrote:

You likely need to "show()" the canvas. I usually do this by
calling "fig.canvas.show()" before the for loop.
Since you are using a Qt4 backend the canvas used by the
figure is a QWidget, the basic component of a Qt4 GUI. I don't
know if there is a more matplotlib specific way of doing this,
but when dealing with a larger system this is how I do it.

I would also add a sleep ("from time import sleep") of a
couple seconds for testing to make sure you are getting
through the entire for loop before you can see it.

Please CC in any replies, thanks.

-Dave


On 3/11/13 8:58 AM, ndbeck...@gmail.com
<mailto:ndbeck...@gmail.com> wrote:

I want to update a plot in real time.  I did some goog
search, and saw various
answers.  Trouble is, they aren't working.

Here's a typical example:

import matplotlib.pyplot as plt
import numpy as np
fig=plt.figure()
plt.axis([0,1000,0,1])

i=0
x=list()
y=list()

while i <1000:
 temp_y=np.random.random()
 x.append(i)
 y.append(temp_y)
 plt.scatter(i,temp_y)
 i+=1
 plt.draw()

If I run this, it draws nothing.

This is my matplotlibrc:
backend : Qt4Agg
mathtext.fontset: stix






--
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] real time plotting

2013-03-11 Thread David Hoese
Oops forgot to change the subject line.

On 3/11/13 9:34 AM, David Hoese wrote:
> You likely need to "show()" the canvas. I usually do this by calling 
> "fig.canvas.show()" before the for loop.
> Since you are using a Qt4 backend the canvas used by the figure is a 
> QWidget, the basic component of a Qt4 GUI. I don't know if there is a 
> more matplotlib specific way of doing this, but when dealing with a 
> larger system this is how I do it.
>
> I would also add a sleep ("from time import sleep") of a couple 
> seconds for testing to make sure you are getting through the entire 
> for loop before you can see it.
>
> Please CC in any replies, thanks.
>
> -Dave
>
> On 3/11/13 8:58 AM, ndbeck...@gmail.com wrote:
>> I want to update a plot in real time.  I did some goog search, and 
>> saw various
>> answers.  Trouble is, they aren't working.
>>
>> Here's a typical example:
>>
>> import matplotlib.pyplot as plt
>> import numpy as np
>> fig=plt.figure()
>> plt.axis([0,1000,0,1])
>>
>> i=0
>> x=list()
>> y=list()
>>
>> while i <1000:
>>  temp_y=np.random.random()
>>  x.append(i)
>>  y.append(temp_y)
>>  plt.scatter(i,temp_y)
>>  i+=1
>>  plt.draw()
>>
>> If I run this, it draws nothing.
>>
>> This is my matplotlibrc:
>> backend : Qt4Agg
>> mathtext.fontset: stix
>


--
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib-users Digest, Vol 82, Issue 16

2013-03-11 Thread David Hoese
You likely need to "show()" the canvas. I usually do this by calling 
"fig.canvas.show()" before the for loop.
Since you are using a Qt4 backend the canvas used by the figure is a 
QWidget, the basic component of a Qt4 GUI. I don't know if there is a 
more matplotlib specific way of doing this, but when dealing with a 
larger system this is how I do it.

I would also add a sleep ("from time import sleep") of a couple seconds 
for testing to make sure you are getting through the entire for loop 
before you can see it.

Please CC in any replies, thanks.

-Dave

On 3/11/13 8:58 AM, ndbeck...@gmail.com wrote:
> I want to update a plot in real time.  I did some goog search, and saw various
> answers.  Trouble is, they aren't working.
>
> Here's a typical example:
>
> import matplotlib.pyplot as plt
> import numpy as np
> fig=plt.figure()
> plt.axis([0,1000,0,1])
>
> i=0
> x=list()
> y=list()
>
> while i <1000:
>  temp_y=np.random.random()
>  x.append(i)
>  y.append(temp_y)
>  plt.scatter(i,temp_y)
>  i+=1
>  plt.draw()
>
> If I run this, it draws nothing.
>
> This is my matplotlibrc:
> backend : Qt4Agg
> mathtext.fontset: stix


--
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] importing basemap then shapely causes error

2013-02-08 Thread David Hoese
I've asked this question on GIS stack exchange site, but thought it 
would be good to post here too.  The SE question is here: 
http://gis.stackexchange.com/questions/50394/importing-matplotlib-basemap-and-shapely


I have a python script that uses matplotlib's basemap and another part 
that uses shapely to do an intersection of 2 polygons. If basemap is 
imported before shapely and I run the intersection I get this exception:


|   intersect_poly=  grid_poly.intersection(data_poly)
File  "/sw/lib/python2.7/site-packages/shapely/geometry/base.py",  line334,  in 
 intersection
  return  geom_factory(self.impl['intersection'](self,  other))
File  "/sw/lib/python2.7/site-packages/shapely/topology.py",  line53,  in  
__call__
  "This operation produced a null geometry. Reason: unknown")
shapely.geos.TopologicalError:  This  operation produced a null geometry.  
Reason:  unknown|

If I import shapely first, everything works fine. I would assume this is 
because of some "funkiness" in the way they are accessing the GEOS 
library. I've checked that in both situations the same library file is 
loaded in shapely ("print shapely.geos._lgeos").


Does anyone have an idea as to why this is happening and if there is a 
right way of doing this? Does this happen for anyone else? In the mean 
time I can just make sure to import shapely first (not sure if that 
affects basemap yet). Otherwise maybe I'll skim through the basemap source.


I'm using OSX(10.7) with a fink install that has "libgeos3.3.3-shlibs", 
"libgeos3.3.1-shlibs", "libgeos3.3.1", "libgeos3.3.0-shlibs", 
"libgeos3.3.0", and "shapely-py27 (1.2.16-1)" installed. The current 
basemap version in fink is 1.0.2.


And here's a simple test script that reproduces the problem (flip the 
imports and it works):


|from  mpl_toolkitsimport  basemap
from  shapelyimport  geometry

g_ring=  [(-88.462425,  26.992203),  (-57.847187,  26.992203),  (-57.847187,  
17.599869),  (-88.462425,  17.599869),  (-88.462425,  26.992203)]
grid_g_ring=  [(-123.044,  59.8440001),  (-49.3849998,  
57.2890001),  (-65.0909994,  14.3350001),  (-113.133,  
16.369),  (-123.044,  59.8440001)]

data_poly=  geometry.Polygon(g_ring)
grid_poly=  geometry.Polygon(grid_g_ring)

print  grid_poly.intersection(data_poly).area|


Thanks again.  Please CC me in any replies.

-Dave
--
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib 1.1 "TypeError: a float is required" problem

2012-01-06 Thread David Hoese

Hi Ken,

You're getting that error because you probably don't have Qt4 installed 
on your Mac (I do).  I'm not sure what backends come with matplotlib and 
will work for you (maybe someone here knows).  You can use any of the 
following:


GTK GTKAgg GTKCairo CocoaAgg FltkAgg
MacOSX QtAgg Qt4Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG Template

Like Qt4, some of those may need to be installed.  I also have Gtk 
installed (never used it before) and "GTKAgg" works for me, but not 
"GTK".  It's also important to know that not all of those backends are 
interactive (they don't all show a window) and the figure must be saved 
to a file.


Also make sure that the 2 lines I provided need to be BEFORE any other 
matplotlib/pyplot imports.  Hope you find something that works for you, 
at least until the macosx bug is fixed.  I'm not an expert, sorry.


-Dave

On 1/6/12 10:35 AM, Mingkui Li wrote:

Hi, Dave,

I tried the two lines of code you posted, but when I ran the example I 
mentioned above I got such error:


ImportError: No module named sip

Seems I can't import any other libs from matplotlib after 
"matplotlib.use("Qt4Agg")"


I'm kind of a newbie, sorry.

Ken


On Sat, Jan 7, 2012 at 12:22 AM, David Hoese <mailto:dho...@gmail.com>> wrote:


I experienced the same problem on the macosx backend, switched to
Qt4Agg
and no problems.

import matplotlib
matplotlib.use("Qt4Agg")

-Dave

On 1/6/12 10:08 AM, md...@stsci.edu <mailto:md...@stsci.edu> wrote:
> I suspect this bug is specific to the macosx backend.  Can you
switch to
> another backend and confirm it doesn't happen there?  (I can't
reproduce
> it on Linux).
>
> Mike



--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a
complex
infrastructure or vast IT resources to deliver seamless, secure
access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI
infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
<mailto:Matplotlib-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/matplotlib-users




--
Mingkui Li



--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib 1.1 "TypeError: a float is required" problem

2012-01-06 Thread David Hoese
I experienced the same problem on the macosx backend, switched to Qt4Agg 
and no problems.

 import matplotlib
 matplotlib.use("Qt4Agg")

-Dave

On 1/6/12 10:08 AM, md...@stsci.edu wrote:
> I suspect this bug is specific to the macosx backend.  Can you switch to
> another backend and confirm it doesn't happen there?  (I can't reproduce
> it on Linux).
>
> Mike


--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Blitting with qt4

2011-12-15 Thread David Hoese
Eric,

Good news I think I got it to work.  So using the same code I sent you 
originally, I applied the following changes:
1. Install matplotlib from git (this did fix things that I wasn't noticing)
2. Add c.draw() before "c.copy_from_bbox"
3. Copy "f.bbox" instead of "a.bbox" (I think this makes sense since I 
want it to hold on to the title,ticks, and labels, a.bbox is only the 
content inside the axis rectangle)
4. Restore f_bbox, blit f.bbox.

...and it seems to work.  The git version of mpl did fix this, although 
restoring just the a.bbox was only keeping the axis rectangle so it made 
it look like even worse of a bug.  Using the new version I noticed this 
and then started using f.bbox which seems to work the way I want it.

Now, my final question is: Is this actually doing what I want 
performance-wise.  When I blit just f.bbox, is it really only repainting 
the updated line or is it redrawing most of the figure?  If you need a 
copy of the new version of my test code let me know.  Thanks for any 
more clarity/help you can give.

-Dave

P.S. Is there a book or tutorial or website where I can learn more about 
how the rendering/painting of stuff like this works.  For example, if I 
could better understand why your bug fix was needed.

On 12/15/11 10:04 AM, David Hoese wrote:
> Oops forgot to change subject.
>
> On 12/15/11 10:02 AM, David Hoese wrote:
>> Eric,
>>
>> I installed mpl from git ("git clone 
>> git://github.com/matplotlib/matplotlib.git", unless I was suppose to 
>> use one of the branches) and same problem.  I looked at my code again 
>> and thought there should be a canvas.draw() before calling 
>> "c.copy_from_bbox(a.bbox)", but still the same problem.  However, I 
>> did have it work the first time I added "c.draw()" and used the git 
>> mpl, and by work I mean that everything stayed visible on the figure.
>>
>> When people start coming in to my work I'll ask them to run my sample 
>> code and see what happens.  It almost seems like mpl is handling the 
>> window activation event funny, is there an easy way to print out the 
>> callbacks being used by a mpl figure?  For now, I will subclass 
>> QApplication, and implement "notify()" to print out events as they 
>> come in, but still...this is just weird.  Thanks.
>>
>> -Dave
>>
>> On 12/14/11 10:30 PM, Eric Firing wrote:
>>> David,
>>>
>>> It works for me on linux with mpl from git.  I haven't tried to figure
>>> it out, but it is conceivable that the problem you are seeing was fixed
>>> with this:
>>>
>>> commit b624546ae60dc5878e75a32f41a160d383548b8f
>>> Author: Eric Firing
>>> Date:   Tue Oct 18 08:06:21 2011 -1000
>>>
>>>   backend_qt4agg: draw() immediately calls FigureCanvasAgg.draw()
>>>
>>>   This is the latest in a series of modifications to the Qt4Agg
>>>   drawing strategy going back several years.  It simplifies the
>>>   code and should solve the problem introduced in 6938b0025; that
>>>   is, delaying the Agg draw operation until the paintEvent breaks
>>>   code expecting that draw operation to have occurred immediately.
>>>   The problem was reported here:
>>>   http://sourceforge.net/mailarchive/message.php?msg_id=28245744
>>>
>>> Eric
>>
>


--
10 Tips for Better Server Consolidation
Server virtualization is being driven by many needs.  
But none more important than the need to reduce IT complexity 
while improving strategic productivity.  Learn More! 
http://www.accelacomm.com/jaw/sdnl/114/51507609/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Blitting with qt4

2011-12-15 Thread David Hoese
Oops forgot to change subject.

On 12/15/11 10:02 AM, David Hoese wrote:
> Eric,
>
> I installed mpl from git ("git clone 
> git://github.com/matplotlib/matplotlib.git", unless I was suppose to 
> use one of the branches) and same problem.  I looked at my code again 
> and thought there should be a canvas.draw() before calling 
> "c.copy_from_bbox(a.bbox)", but still the same problem.  However, I 
> did have it work the first time I added "c.draw()" and used the git 
> mpl, and by work I mean that everything stayed visible on the figure.
>
> When people start coming in to my work I'll ask them to run my sample 
> code and see what happens.  It almost seems like mpl is handling the 
> window activation event funny, is there an easy way to print out the 
> callbacks being used by a mpl figure?  For now, I will subclass 
> QApplication, and implement "notify()" to print out events as they 
> come in, but still...this is just weird.  Thanks.
>
> -Dave
>
> On 12/14/11 10:30 PM, Eric Firing wrote:
>> David,
>>
>> It works for me on linux with mpl from git.  I haven't tried to figure
>> it out, but it is conceivable that the problem you are seeing was fixed
>> with this:
>>
>> commit b624546ae60dc5878e75a32f41a160d383548b8f
>> Author: Eric Firing
>> Date:   Tue Oct 18 08:06:21 2011 -1000
>>
>>   backend_qt4agg: draw() immediately calls FigureCanvasAgg.draw()
>>
>>   This is the latest in a series of modifications to the Qt4Agg
>>   drawing strategy going back several years.  It simplifies the
>>   code and should solve the problem introduced in 6938b0025; that
>>   is, delaying the Agg draw operation until the paintEvent breaks
>>   code expecting that draw operation to have occurred immediately.
>>   The problem was reported here:
>>   http://sourceforge.net/mailarchive/message.php?msg_id=28245744
>>
>> Eric
>


--
10 Tips for Better Server Consolidation
Server virtualization is being driven by many needs.  
But none more important than the need to reduce IT complexity 
while improving strategic productivity.  Learn More! 
http://www.accelacomm.com/jaw/sdnl/114/51507609/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib-users Digest, Vol 67, Issue 23

2011-12-15 Thread David Hoese
Eric,

I installed mpl from git ("git clone 
git://github.com/matplotlib/matplotlib.git", unless I was suppose to use 
one of the branches) and same problem.  I looked at my code again and 
thought there should be a canvas.draw() before calling 
"c.copy_from_bbox(a.bbox)", but still the same problem.  However, I did 
have it work the first time I added "c.draw()" and used the git mpl, and 
by work I mean that everything stayed visible on the figure.

When people start coming in to my work I'll ask them to run my sample 
code and see what happens.  It almost seems like mpl is handling the 
window activation event funny, is there an easy way to print out the 
callbacks being used by a mpl figure?  For now, I will subclass 
QApplication, and implement "notify()" to print out events as they come 
in, but still...this is just weird.  Thanks.

-Dave

On 12/14/11 10:30 PM, Eric Firing wrote:
> David,
>
> It works for me on linux with mpl from git.  I haven't tried to figure
> it out, but it is conceivable that the problem you are seeing was fixed
> with this:
>
> commit b624546ae60dc5878e75a32f41a160d383548b8f
> Author: Eric Firing
> Date:   Tue Oct 18 08:06:21 2011 -1000
>
>   backend_qt4agg: draw() immediately calls FigureCanvasAgg.draw()
>
>   This is the latest in a series of modifications to the Qt4Agg
>   drawing strategy going back several years.  It simplifies the
>   code and should solve the problem introduced in 6938b0025; that
>   is, delaying the Agg draw operation until the paintEvent breaks
>   code expecting that draw operation to have occurred immediately.
>   The problem was reported here:
>   http://sourceforge.net/mailarchive/message.php?msg_id=28245744
>
> Eric


--
10 Tips for Better Server Consolidation
Server virtualization is being driven by many needs.  
But none more important than the need to reduce IT complexity 
while improving strategic productivity.  Learn More! 
http://www.accelacomm.com/jaw/sdnl/114/51507609/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Blitting with qt4

2011-12-14 Thread David Hoese
Does anyone know if using the blit method from FigureCanvasQTAgg is not 
fully supported?  I'm having a problem where I'm animating a plot using 
the blit method and I click on/activate the window the background of the 
figure disappears (axes and line stay visible).  I'm not sure if this is 
just me (Mac OS X Lion, Qt4 4.8.6, Matplotlib 1.1.0), but the following 
code reproduces the error:

###
from PyQt4 import QtGui,QtCore
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from time import sleep

app = QtGui.QApplication([" "])
f = Figure()
c = FigureCanvasQTAgg(f)
a = f.add_subplot(111)
a.set_title("A Title")
bbox = c.copy_from_bbox(a.bbox)
lines = a.plot([1,2,3],[1,2,3])
c.draw()
c.show()

wait = raw_input("Press a key to continue...")

def update(i):
 a.lines[0].set_ydata([i,1,i])
 print a.bbox.bounds
 c.restore_region(bbox, bbox=a.bbox)
 a.draw_artist(a.lines[0])
 c.blit(a.bbox)

 sleep(1)
 app.processEvents()

for i in range(20):
 update(i)

wait = raw_input("Press a key to continue...")
###

To see the problem, run the code, watch the plot to make sure its 
updating properly, then click on the window  to put it in focus/activate 
it.  I'm hoping that I'm just doing something stupid and its an easy 
fix.  It seems to work until I click on the window (in Mac OS X Lion 
Terminal the window is opened in the background and the Terminal window 
stays in focus).  Thanks for any help.

-Dave


--
Cloud Computing - Latest Buzzword or a Glimpse of the Future?
This paper surveys cloud computing today: What are the benefits? 
Why are businesses embracing it? What are its payoffs and pitfalls?
http://www.accelacomm.com/jaw/sdnl/114/51425149/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [ploting data] Live data

2011-12-14 Thread David Hoese
I don't know what you mean by "ApplicationWindow", is that a class or 
just a name for the main GUI window.  I also don't really know what 
calling the graphical application means, but I'm sure the book can help 
you more than I can.  Again, good luck.

-Dave

On 12/14/11 10:17 AM, Fabien Lafont wrote:
> Thanks David, I start to read the Mark summerfield' book about PyQt
> programming.
>
> In fact I realized I don't need multi-threading because I can remove
> the Timer and just need to call the graphical application from the
> while loop.
>
> How can I call the "ApplicationWindow" class from my while loop? I'll
> try to read a bit more about PyQt to understand how it works :)
>
> thanks again!
>
> Fabien
>
> 2011/12/14 David Hoese:
>> I'm not sure how experienced you are with multithreaded programs, but here
>> is some sample code (I mentioned it can get complicated).  I suggest you
>> research Qt4 QThreads and also Qt4 Signals and slots to better understand
>> the code below.  It is a working sample so you should be able to run it in a
>> terminal and notice that the GUI is responsive and that you have messages
>> being printed out on the terminal.  The code I provided below is more
>> complicated than you may need for a proof-of-concept kind of program, but if
>> you will be communicating with physical devices I suggest something like
>> this.  I am by no means and expert, but I have been doing something similar
>> to what you are doing.  I also suggest maybe separating the device
>> communication into another module/class, especially if others are going to
>> (re)use your code.
>>
>> Good Luck,
>> Dave
>>
>> P.S. There are a lot of Qt4/PyQt4 threading examples online, but not all of
>> them correct.  What I posted below is what I have found to be considered
>> "correct" by most people.
>>
>> #
>> ### Sample Code ###
>> #
>>
>> import time
>> from PyQt4 import QtGui,QtCore
>>
>> class MyWindow(QtGui.QWidget):
>> def __init__(self):
>> QtGui.QWidget.__init__(self)
>>
>> # Sample GUI elements to test responsiveness
>> the_choices = ["item"]*20
>> self.choices = QtGui.QComboBox()
>> self.choices.addItems(the_choices)
>> self.layout = QtGui.QVBoxLayout(self)
>> self.layout.addWidget(self.choices)
>> self.setLayout(self.layout)
>>
>> def handle_new_data(self):
>> # This is where you could redraw any matplotlib plots
>> # Maybe send data through the signal/slot connection
>> print "Updating data"
>>
>> class MyInstrument(QtCore.QObject):
>> signal_new_data = QtCore.pyqtSignal(name="signal_new_data")
>> signal_closing = QtCore.pyqtSignal(name="signal_closing")
>> def run(self):
>> self._timer = QtCore.QTimer()
>> self._timer.timeout.connect(self._run)
>> self._timer.start(0)
>>
>> def _run(self):
>> time.sleep(1)
>> print "Running the instrument function"
>> time.sleep(1)
>> self.signal_new_data.emit()
>>
>> def close(self):
>> print "Closing instrument thread"
>> self._timer.stop()
>> # Redundant timer stop
>> self._timer.timeout.disconnect()
>> self.signal_closing.emit()
>>
>> if __name__ == "__main__":
>> app = QtGui.QApplication([" "])
>> w = MyWindow()
>> w.show()
>> instrument = MyInstrument()
>> instrument_thread = QtCore.QThread()
>> instrument.moveToThread(instrument_thread)
>>
>> instrument_thread.started.connect(instrument.run)
>> instrument.signal_new_data.connect(w.handle_new_data)
>>
>> # Make the close function run in the main thread so you can "interrupt"
>> the sleeps
>> app.lastWindowClosed.connect(instrument.close,
>> QtCore.Qt.DirectConnection)
>> # You could also call quit "manually" after exec_() returns
>> instrument.signal_closing.connect(instrument_thread.quit)
>>
>> instrument_thread.start()
>> app.exec_()
>> #instrument_thread.quit()
>>
>> print "Waiting for instrument thread..."
>> instrument_thread.wait()
>> print "SUCCESS"
>>
>> ##
>> ### End of Sample Code ###
>> #

Re: [Matplotlib-users] [ploting data] Live data

2011-12-14 Thread David Hoese
I'm not sure how experienced you are with multithreaded programs, but 
here is some sample code (I mentioned it can get complicated).  I 
suggest you research Qt4 QThreads and also Qt4 Signals and slots to 
better understand the code below.  It is a working sample so you should 
be able to run it in a terminal and notice that the GUI is responsive 
and that you have messages being printed out on the terminal.  The code 
I provided below is more complicated than you may need for a 
proof-of-concept kind of program, but if you will be communicating with 
physical devices I suggest something like this.  I am by no means and 
expert, but I have been doing something similar to what you are doing.  
I also suggest maybe separating the device communication into another 
module/class, especially if others are going to (re)use your code.

Good Luck,
Dave

P.S. There are a lot of Qt4/PyQt4 threading examples online, but not all 
of them correct.  What I posted below is what I have found to be 
considered "correct" by most people.

#
### Sample Code ###
#

import time
from PyQt4 import QtGui,QtCore

class MyWindow(QtGui.QWidget):
 def __init__(self):
 QtGui.QWidget.__init__(self)

 # Sample GUI elements to test responsiveness
 the_choices = ["item"]*20
 self.choices = QtGui.QComboBox()
 self.choices.addItems(the_choices)
 self.layout = QtGui.QVBoxLayout(self)
 self.layout.addWidget(self.choices)
 self.setLayout(self.layout)

 def handle_new_data(self):
 # This is where you could redraw any matplotlib plots
 # Maybe send data through the signal/slot connection
 print "Updating data"

class MyInstrument(QtCore.QObject):
 signal_new_data = QtCore.pyqtSignal(name="signal_new_data")
 signal_closing = QtCore.pyqtSignal(name="signal_closing")
 def run(self):
 self._timer = QtCore.QTimer()
 self._timer.timeout.connect(self._run)
 self._timer.start(0)

 def _run(self):
 time.sleep(1)
 print "Running the instrument function"
 time.sleep(1)
 self.signal_new_data.emit()

 def close(self):
 print "Closing instrument thread"
 self._timer.stop()
 # Redundant timer stop
 self._timer.timeout.disconnect()
 self.signal_closing.emit()

if __name__ == "__main__":
 app = QtGui.QApplication([" "])
 w = MyWindow()
 w.show()
 instrument = MyInstrument()
 instrument_thread = QtCore.QThread()
 instrument.moveToThread(instrument_thread)

 instrument_thread.started.connect(instrument.run)
 instrument.signal_new_data.connect(w.handle_new_data)

 # Make the close function run in the main thread so you can 
"interrupt" the sleeps
 app.lastWindowClosed.connect(instrument.close, 
QtCore.Qt.DirectConnection)
 # You could also call quit "manually" after exec_() returns
 instrument.signal_closing.connect(instrument_thread.quit)

 instrument_thread.start()
 app.exec_()
 #instrument_thread.quit()

 print "Waiting for instrument thread..."
 instrument_thread.wait()
 print "SUCCESS"

##
### End of Sample Code ###
##

On 12/14/11 3:51 AM, Fabien Lafont wrote:
> I prefer to use the multi-thread method beacause it's easier for me
> and my colaborators to have the entire acquisition process at the same
> place. Until then I use a simple one but I hope to use a more complex
> one in few weeks ( put different voltages on different devices then
> measure many voltages or current). If I use the "domino" technique
> (call the next operation by the end of the previous) it can be complex
> to read and to edit. Thank you very much anyway!
>
> How can I write a multi-thread process? I've just tried to add
> qApp.processEvents() at the end of my while loop but it doesn't change
> anything...
>
> Thanks again,
>
> Fabien
>
> 2011/12/13 David Hoese:
>> Yeah I didn't think about suggesting that, but I think it might get
>> complicated.  I think he would have to start a one shot timer to call a
>> function to set the voltage.  Then that function would also start another
>> one shot timer to call another function that would read from the sample.
>>   That function then would start a one shot timer to call the first function
>> again.  This way he can be sure that things are called in order and that
>> timing is consistent, just in case the GUI gets complicated or something
>> makes the event loop slow down.
>>
>> He could also use multiple threads.  Whatever works for Fabien I guess.
>>
>> -Dave
>>
>> On 12/13/11 1:00 PM, ma

Re: [Matplotlib-users] [ploting data] Live data

2011-12-13 Thread David Hoese
Yeah I didn't think about suggesting that, but I think it might get 
complicated.  I think he would have to start a one shot timer to call a 
function to set the voltage.  Then that function would also start 
another one shot timer to call another function that would read from the 
sample.  That function then would start a one shot timer to call the 
first function again.  This way he can be sure that things are called in 
order and that timing is consistent, just in case the GUI gets 
complicated or something makes the event loop slow down.

He could also use multiple threads.  Whatever works for Fabien I guess.

-Dave

On 12/13/11 1:00 PM, matplotlib-users-requ...@lists.sourceforge.net wrote:
> From: "Drain, Theodore R (343P)"
> Subject: Re: [Matplotlib-users] [ploting data] Live data
>
> Perhaps I'm missing something, but why not use QTimer?  You can't really 
> every call sleep in a single threaded gui (for reasons you've encountered).  
> If you need to poll something, create a QTimer for 2 seconds and have it call 
> a measurement function to update the data.  You shouldn't need any 
> processEvents calls or sleep.


--
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and 
improve service delivery. Take 5 minutes to use this Systems Optimization 
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [ploting data] Live data

2011-12-13 Thread David Hoese
Fabien,

The GUI not being responsive might be my fault, I've never used a timer 
of 0 and processEvents().  I think what might be happening is that when
you call processEvents, the timer of 0 calls your principal function 
again, which calls processEvents again, and so on.  Try a timer of 2 
again, that "should" stop the timer from being constantly triggered. 
Later today, once I get to work, I'll run some tests of my own and 
figure out if that's really the problem.  Email me if you make any progress.

-Dave

On 12/13/2011 2:30 AM, Fabien Lafont wrote:
> Hey David,
>
> I'm doing this program to control an experiment, so I want to put the
> voltage on the sample, then wait two seconds to be sure there is no
> current fluctuations then measure the curent with multimeters and
> finally plot the datas. That's why I need the "sleep"... In fact I
> wanted to use in parallel the timer to "refresh" the graph and a while
> loop to "extract" the datas.
>
> If I use startTimer(0) it works but the GUI is almost unresponsive.
> I'm trying to use qApp.processEvents() but up to now I don't manage to
> see the window appears...
>
> Thanks again for your help
>
> Fabien
>
>
>
> 2011/12/12 David Hoese:
>> Hey Fabien,
>>
>> So you made your principal function run on a timer every 2 seconds?  And by
>> "lag" do you mean that the GUI is unresponsive?  I'm still not seeing when
>> the loop stops, but what you can do is set the timer at a 0 interval so it
>> will call the principal function as fast as it can (but with no loop).  The
>> problem with this is that you have those 2 sleep calls in the function.  I'm
>> not sure why you have the sleeps, but if you need them you have two choices:
>>
>> 1. Make you GUI multi-threaded and you could emit a Qt signal from the data
>> thread when the GUI thread needs to update the GUI.  Yes this could get
>> complicated, but if the sleeps are required then its probably the best way.
>>
>> 2. (From what I've been told, the Qt experts don't approve this) You can use
>> app.processEvents() in your loop (after each sleep maybe) and this will
>> pause your function and tell the main event loop to process any queued
>> events (like GUI actions/events) which will make your GUI more responsive.
>>
>> If that doesn't make sense let me know.
>>
>> -Dave
>>
>>
>> On 12/12/11 9:16 AM, Fabien Lafont wrote:
>>>
>>> Hi David! Sorry about the delay I was abroad and without any way to
>>> connect to the internet.
>>>
>>> Thank you very much. I've tried to put the principal inside the
>>> timerEvent. It work but it lags. In fact I've set the interval of the
>>> Timer to 2 seconds because the principal loop takes roughly 2seconds
>>> but it's not very accurate...
>>>
>>> Is there a way to do the principal loop, show it on the screen, then
>>> redo the loop?
>>>
>>> Thanks again!
>>>
>>> Fabien
>>>
>>> 2011/12/5 David Hoese:
>>>>
>>>> If I'm understanding your question correctly and reading your code
>>>> correctly, you're asking why the timer method of doing things works, but 
>>>> the
>>>> principal() while loop method does not.
>>>>
>>>> I had a couple solutions that involved the main event loop, but I just
>>>> noticed 2 main things that are probably wrong with your code:
>>>> 1. You are calling 'principal' from inside __init__ so you never actually
>>>> return from __init__ which means that you never call "window.show()" and
>>>> therefore never call "qApp.exec_()".  If you really want to use the
>>>> 'principal' method you would have to connect it to a one shot timer anyway
>>>> to have it run after you have started the application ('qApp.exec_()').  I
>>>> think the recommended way would be to use the timer the way you did in your
>>>> latest email.
>>>>
>>>> 2. At least in the way my email client reads your original code, your
>>>> calls to the matplotlib drawing functions aren't inside the while loop and
>>>> the while loop never ends...although this doesn't matter if you don't fix 
>>>> #1
>>>> above.
>>>>
>>>> Hope that made sense.
>>>>
>>>> -Dave
>>>>
>>>>
>>>&

Re: [Matplotlib-users] [ploting data] Live data

2011-12-12 Thread David Hoese
Hey Fabien,

So you made your principal function run on a timer every 2 seconds?  And 
by "lag" do you mean that the GUI is unresponsive?  I'm still not seeing 
when the loop stops, but what you can do is set the timer at a 0 
interval so it will call the principal function as fast as it can (but 
with no loop).  The problem with this is that you have those 2 sleep 
calls in the function.  I'm not sure why you have the sleeps, but if you 
need them you have two choices:

1. Make you GUI multi-threaded and you could emit a Qt signal from the 
data thread when the GUI thread needs to update the GUI.  Yes this could 
get complicated, but if the sleeps are required then its probably the 
best way.

2. (From what I've been told, the Qt experts don't approve this) You can 
use app.processEvents() in your loop (after each sleep maybe) and this 
will pause your function and tell the main event loop to process any 
queued events (like GUI actions/events) which will make your GUI more 
responsive.

If that doesn't make sense let me know.

-Dave

On 12/12/11 9:16 AM, Fabien Lafont wrote:
> Hi David! Sorry about the delay I was abroad and without any way to
> connect to the internet.
>
> Thank you very much. I've tried to put the principal inside the
> timerEvent. It work but it lags. In fact I've set the interval of the
> Timer to 2 seconds because the principal loop takes roughly 2seconds
> but it's not very accurate...
>
> Is there a way to do the principal loop, show it on the screen, then
> redo the loop?
>
> Thanks again!
>
> Fabien
>
> 2011/12/5 David Hoese:
>> If I'm understanding your question correctly and reading your code 
>> correctly, you're asking why the timer method of doing things works, but the 
>> principal() while loop method does not.
>>
>> I had a couple solutions that involved the main event loop, but I just 
>> noticed 2 main things that are probably wrong with your code:
>> 1. You are calling 'principal' from inside __init__ so you never actually 
>> return from __init__ which means that you never call "window.show()" and 
>> therefore never call "qApp.exec_()".  If you really want to use the 
>> 'principal' method you would have to connect it to a one shot timer anyway 
>> to have it run after you have started the application ('qApp.exec_()').  I 
>> think the recommended way would be to use the timer the way you did in your 
>> latest email.
>>
>> 2. At least in the way my email client reads your original code, your calls 
>> to the matplotlib drawing functions aren't inside the while loop and the 
>> while loop never ends...although this doesn't matter if you don't fix #1 
>> above.
>>
>> Hope that made sense.
>>
>> -Dave
>>
>>
>> On 12/5/11 1:44 PM, matplotlib-users-requ...@lists.sourceforge.net wrote:
>>> Message: 3
>>> Date: Mon, 5 Dec 2011 15:46:02 +0100
>>> From: Fabien Lafont
>>> Subject: Re: [Matplotlib-users] [ploting data] Live data
>>> Cc:matplotlib-users@lists.sourceforge.net
>>> Message-ID:
>>>
>>> Content-Type: text/plain; charset=ISO-8859-1
>>>
>>> Thx all for your remarks,
>>>
>>> I can't understand why this code works (when I use the timer method):
>>
>> --
>> All the data continuously generated in your IT infrastructure
>> contains a definitive record of customers, application performance,
>> security threats, fraudulent activity, and more. Splunk takes this
>> data and makes sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-novd2d
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [ploting data] Live data

2011-12-05 Thread David Hoese
If I'm understanding your question correctly and reading your code correctly, 
you're asking why the timer method of doing things works, but the principal() 
while loop method does not.

I had a couple solutions that involved the main event loop, but I just noticed 
2 main things that are probably wrong with your code:
1. You are calling 'principal' from inside __init__ so you never actually 
return from __init__ which means that you never call "window.show()" and 
therefore never call "qApp.exec_()".  If you really want to use the 'principal' 
method you would have to connect it to a one shot timer anyway to have it run 
after you have started the application ('qApp.exec_()').  I think the 
recommended way would be to use the timer the way you did in your latest email.

2. At least in the way my email client reads your original code, your calls to 
the matplotlib drawing functions aren't inside the while loop and the while 
loop never ends...although this doesn't matter if you don't fix #1 above.

Hope that made sense.

-Dave


On 12/5/11 1:44 PM, matplotlib-users-requ...@lists.sourceforge.net wrote:
> Message: 3
> Date: Mon, 5 Dec 2011 15:46:02 +0100
> From: Fabien Lafont
> Subject: Re: [Matplotlib-users] [ploting data] Live data
> Cc:matplotlib-users@lists.sourceforge.net
> Message-ID:
>   
> Content-Type: text/plain; charset=ISO-8859-1
>
> Thx all for your remarks,
>
> I can't understand why this code works (when I use the timer method):


--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [ploting data] Live data

2011-12-04 Thread David Hoese
I think you forget to set the layout on your central widget.

self.main_widget.setLayout(vbl) # in your case

-Dave

On 12/4/2011 9:57 AM, matplotlib-users-requ...@lists.sourceforge.net wrote:
> 2011/12/2 Daniel Hyams:
>> >  I don't have PyQt installed, so I couldn't test the code, but don't you 
>> > want
>> >  to be using "extend" and not "append", if you are returning a list from 
>> > your
>> >  two get_info() functions?
>> >
>> >  On Fri, Dec 2, 2011 at 8:13 AM, Fabien Lafont
>> >  wrote:
>>> >>
>>> >>  Hello everyone, I'm trying to plot live data extracting from remote
>>> >>  devices (here it's simulated by get_info1 and 2 the result is always
>>> >>  0.8 or 0.9
>>> >>
>>> >>  I can't understand why it doesnt plot the graph at the end of the
>>> >>  while loop. Does somebody has an idea?

--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how would you do this (animated bargraph) (Neal Becker)

2011-09-30 Thread David Hoese
Neal,

I do something similar to this where data that I'm plotting in a 2D line 
plot comes from a UDP socket and some memory mapped files.  To 
accomplish the live updating I have a mix of your #2 and #3.  I have a 
main GUI thread that displays the plots, then I have a second thread 
that gets data from a python generator and signals the GUI thread when 
that new data has arrived.  Inside the generator is where I have socket 
communications and select calls.  Hope this helps.

-Dave

On 9/30/11 9:10 AM, matplotlib-users-requ...@lists.sourceforge.net wrote:
> Message: 4
> Date: Fri, 30 Sep 2011 07:37:49 -0400
> From: Neal Becker
> Subject: [Matplotlib-users] how would you do this (animated bargraph)
> To:matplotlib-users@lists.sourceforge.net
> Message-ID:
> Content-Type: text/plain; charset="ISO-8859-1"
>
> I just put together an animated bargraph to show results from a realtime
> process.
>
> I used this as an example:
> http://matplotlib.sourceforge.net/examples/animation/animation_blit_qt4.html
>
> The tricky part for me was that in the original design, there was a realtime
> process running.  I have to write some information to my hardware (at a rate 
> of
> about 1/360ms).  To do this, I have a kernel driver that uses 'read' to tell 
> the
> user space when an interrupt has occurred, which is when the user space should
> write new information to the hardware.
>
> So I don't know how or if this could be hooked into qt event processing.  Just
> for a quick-and-dirty demo, I just removed the realtime processing from the
> user-space and put it in the kernel driver, so now my bargraph display can
> simply update on a periodic timer, and the userspace code has no realtime
> requirement.  But this is just a kludge.
>
> So I wonder how other's would solve this?  I'm thinking it would be either:
>
> 1) multi-process
> 2) multi-thread
> 3) 1 process, but somehow hook my realtime events into qt's event loop.
>
> For #3, my device driver has a filedescriptor, that could use select to detect
> the interrupt (rather than blocking read call).
>
> #1 and #2 seem complicated.

--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users