[Matplotlib-users] dynamic plottinng

2013-09-19 Thread Bruno Pace
Hi all,

I am trying to plot the time evolution of a probability distribution, but I
don't know how to use it. I have a different histogram for each time step.
I tried plt.ion()  but I'm not sure how to use it. I'm sure it must be a
simple solution, but I haven't really found out how to do it! If I use
plt.show() as written below, I have to close the window every time for it
to reopen. Here is my code, can you help me?

import matplotlib.pyplot as plt
import numpy
import math

def p(N, Na, fa,  fb):
return float(Na)*fa/(Na*fa + (N-Na)*fb)

def binomial(n,k):
   if k > n-k:
   k = n-k
   accum = 1
   for i in range(1,k+1):
  accum *= (n - (k - i))
  accum /= i
   return accum

def pk(N, k, p):
return binomial(N, k)*math.pow(p,k)*math.pow((1-p),(N-k))

def expected(N, dist):
soma = 0
for k in range(N + 1):
soma += k*dist[k]
return soma

def drawhist(menMeans):

N = len(menMeans)

ind = numpy.arange(N)

width = 1.0

plt.clf()

plt.ylabel('Probability')
plt.xlabel('k')
plt.xlim(0.0,N)
plt.ylim(0.0,1.0)
plt.bar(ind, menMeans, width)
plt.draw()
plt.show()



N = 100
Na = 50
fa = 10
fb = 5



pks = [0]*(N+1)
pks[Na] = 1
pkst = [0]*(N+1)
expect = [Na]

drawhist(pks)
p = [p(N, n, fa, fb) for n in range(N + 1)]

for t in range(5):
for Na in range(N + 1):
for k in range(N + 1):
pkst[k] += pks[Na]*pk(N, k, p[Na])
drawhist(pkst)
pks = pkst
pkst = [0]*(N+1)
expect.append(expected(N, pks))
--
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to control the y feedback value?

2013-09-19 Thread Skip Montanaro
> I assume that you are using a twinx call to get the second y axis.  I think 
> that this question has come up before, and I think the solution was to switch 
> which data are put on the second set of axes.  (Of course to keep the same 
> visual layout you would have to play with the y axis spine locations.)

Good point.  I just changed the command line options so the plot whose
Y values are of interest are plotted on the right Y axis.

> Separately, if your blue data are so quantized, you might use the blue data 
> to choose a color for an axvspan (or axhspan, I  forget which is which) to 
> indicate how certain regions of time have different values of blue data.  
> Then you would only need one set of axes, and your x,y labels would indicate 
> what you want.

This also works, though I (and anyone looking at the graph) would have
to remember the mapping between color and numeric value. If I was a
synethete this might work, but I doubt most people would automatically
recall the mapping. :-)

Thx,

Skip

--
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to control the y feedback value?

2013-09-19 Thread Sterling Smith

On Sep 19, 2013, at 10:14AM, Skip Montanaro wrote:
> 
>> Separately, if your blue data are so quantized, you might use the blue data 
>> to choose a color for an axvspan (or axhspan, I  forget which is which) to 
>> indicate how certain regions of time have different values of blue data.  
>> Then you would only need one set of axes, and your x,y labels would indicate 
>> what you want.
> 
> This also works, though I (and anyone looking at the graph) would have
> to remember the mapping between color and numeric value. If I was a
> synethete this might work, but I doubt most people would automatically
> recall the mapping. :-)

No assumption of super-human recollection or inference abilities . I would add 
a figure or axes legend with proxy artists for the appropriate color mappings, 
or even just a bunch of text boxes with the text label colored appropriately.  
You may be interested in my answer to a stackoverflow question [1].

-Sterling

[1] 
http://stackoverflow.com/questions/17086847/box-around-text-in-matplotlib/17092777#17092777
--
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to control the y feedback value?

2013-09-19 Thread Sterling Smith
Skip,

I assume that you are using a twinx call to get the second y axis.  I think 
that this question has come up before, and I think the solution was to switch 
which data are put on the second set of axes.  (Of course to keep the same 
visual layout you would have to play with the y axis spine locations.)  

Separately, if your blue data are so quantized, you might use the blue data to 
choose a color for an axvspan (or axhspan, I  forget which is which) to 
indicate how certain regions of time have different values of blue data.  Then 
you would only need one set of axes, and your x,y labels would indicate what 
you want.

-Sterling

On Sep 19, 2013, at 7:46AM, Skip Montanaro wrote:

> I have a plot which uses both the left and right y axes.  See
> attached. Note that the feedback in the lower right-hand corner
> displays the value on the right y axis (the blue plot). That's not a
> very interesting value though. How can I control which value is
> displayed as I move the cursor around the graph? Is it something
> control interactively with a modifier key?  I tried a few, but saw no
> change. I'm currently using matplotlib v 1.1.0 (alas, something which
> is also out of my control).
> 
> Thanks,
> 
> Skip
> --
> LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
> 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
> 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
> Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
> http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] datestr2num of year and month

2013-09-19 Thread Mark Bakker
Hello List,

When I use datestr2num('2010-05') it nicely converts that to a number
representing the date.
When I convert that number back with num2date, it turns out it sets the day
to the 19th of the month. The dime is 0:00:00.
Any reason it is set to the 19th instead of the first?
Maybe because today it the 19th, or is that just a coincidence?

Thanks,

Mark
--
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] datestr2num of year and month

2013-09-19 Thread Goyo
2013/9/19 Mark Bakker :
> Hello List,
>
> When I use datestr2num('2010-05') it nicely converts that to a number
> representing the date.
> When I convert that number back with num2date, it turns out it sets the day
> to the 19th of the month. The dime is 0:00:00.
> Any reason it is set to the 19th instead of the first?
> Maybe because today it the 19th, or is that just a coincidence?

datestr2num calls dateutil.parser.parse, which by default uses the
current date at 00:00:00 for missing fields. The dateutil function
also can use a "default" argument to change this bahavoir but it is
not available in datestr2num.

http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c

Goyo

--
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users