You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
(12) |
Sep
(12) |
Oct
(56) |
Nov
(65) |
Dec
(37) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(59) |
Feb
(78) |
Mar
(153) |
Apr
(205) |
May
(184) |
Jun
(123) |
Jul
(171) |
Aug
(156) |
Sep
(190) |
Oct
(120) |
Nov
(154) |
Dec
(223) |
| 2005 |
Jan
(184) |
Feb
(267) |
Mar
(214) |
Apr
(286) |
May
(320) |
Jun
(299) |
Jul
(348) |
Aug
(283) |
Sep
(355) |
Oct
(293) |
Nov
(232) |
Dec
(203) |
| 2006 |
Jan
(352) |
Feb
(358) |
Mar
(403) |
Apr
(313) |
May
(165) |
Jun
(281) |
Jul
(316) |
Aug
(228) |
Sep
(279) |
Oct
(243) |
Nov
(315) |
Dec
(345) |
| 2007 |
Jan
(260) |
Feb
(323) |
Mar
(340) |
Apr
(319) |
May
(290) |
Jun
(296) |
Jul
(221) |
Aug
(292) |
Sep
(242) |
Oct
(248) |
Nov
(242) |
Dec
(332) |
| 2008 |
Jan
(312) |
Feb
(359) |
Mar
(454) |
Apr
(287) |
May
(340) |
Jun
(450) |
Jul
(403) |
Aug
(324) |
Sep
(349) |
Oct
(385) |
Nov
(363) |
Dec
(437) |
| 2009 |
Jan
(500) |
Feb
(301) |
Mar
(409) |
Apr
(486) |
May
(545) |
Jun
(391) |
Jul
(518) |
Aug
(497) |
Sep
(492) |
Oct
(429) |
Nov
(357) |
Dec
(310) |
| 2010 |
Jan
(371) |
Feb
(657) |
Mar
(519) |
Apr
(432) |
May
(312) |
Jun
(416) |
Jul
(477) |
Aug
(386) |
Sep
(419) |
Oct
(435) |
Nov
(320) |
Dec
(202) |
| 2011 |
Jan
(321) |
Feb
(413) |
Mar
(299) |
Apr
(215) |
May
(284) |
Jun
(203) |
Jul
(207) |
Aug
(314) |
Sep
(321) |
Oct
(259) |
Nov
(347) |
Dec
(209) |
| 2012 |
Jan
(322) |
Feb
(414) |
Mar
(377) |
Apr
(179) |
May
(173) |
Jun
(234) |
Jul
(295) |
Aug
(239) |
Sep
(276) |
Oct
(355) |
Nov
(144) |
Dec
(108) |
| 2013 |
Jan
(170) |
Feb
(89) |
Mar
(204) |
Apr
(133) |
May
(142) |
Jun
(89) |
Jul
(160) |
Aug
(180) |
Sep
(69) |
Oct
(136) |
Nov
(83) |
Dec
(32) |
| 2014 |
Jan
(71) |
Feb
(90) |
Mar
(161) |
Apr
(117) |
May
(78) |
Jun
(94) |
Jul
(60) |
Aug
(83) |
Sep
(102) |
Oct
(132) |
Nov
(154) |
Dec
(96) |
| 2015 |
Jan
(45) |
Feb
(138) |
Mar
(176) |
Apr
(132) |
May
(119) |
Jun
(124) |
Jul
(77) |
Aug
(31) |
Sep
(34) |
Oct
(22) |
Nov
(23) |
Dec
(9) |
| 2016 |
Jan
(26) |
Feb
(17) |
Mar
(10) |
Apr
(8) |
May
(4) |
Jun
(8) |
Jul
(6) |
Aug
(5) |
Sep
(9) |
Oct
(4) |
Nov
|
Dec
|
| 2017 |
Jan
(5) |
Feb
(7) |
Mar
(1) |
Apr
(5) |
May
|
Jun
(3) |
Jul
(6) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
1
|
2
(13) |
3
(5) |
4
(5) |
5
(21) |
6
(10) |
7
(9) |
|
8
(4) |
9
(11) |
10
(9) |
11
(11) |
12
(25) |
13
(5) |
14
(2) |
|
15
(5) |
16
(8) |
17
(16) |
18
(11) |
19
(15) |
20
(5) |
21
(8) |
|
22
(4) |
23
(24) |
24
(9) |
25
(14) |
26
(5) |
27
(28) |
28
(2) |
|
29
(13) |
30
(14) |
31
(11) |
|
|
|
|
|
From: Mike M. <mmu...@py...> - 2012-01-24 20:52:29
|
Course "Python for Scientists and Engineers" in Chicago ======================================================= There will be a comprehensive Python course for scientists and engineers in Chicago end of February / beginning of March 2012. It consists of a 3-day intro and a 2-day advanced section. Both sections can be taken separately or combined. More details below and here: http://www.dabeaz.com/chicago/science.html Please let friends or colleagues who might be interested in such a course know about it. 3-Day Intro Section ------------------- - Overview of Scientific and Technical Libraries for Python. - Numerical Calculations with NumPy - Storage and Processing of Large Amounts of Data - Graphical Presentation of Scientific Data with matplotlib - Object Oriented Programming for Scientific and Technical Projects - Open Time for Problem Solving 2-Day Advanced Section ---------------------- - Extending Python with Other Languages - Unit Testing - Version Control with Mercurial The Details ----------- The course is hosted by David Beazley (http://www.dabeaz.com). Date: Feb 27 - Mar 2, 2012 Location: Chicago, IL, USA Trainer: Mike Müller Course Language: English Link: http://www.dabeaz.com/chicago/science.html |
|
From: alw46 <ama...@gm...> - 2012-01-24 20:40:12
|
Hi Eric, First, thanks for the sample - I agree that it's a neat example and I really appreciate the help. Second, I've tried to adapt your code to my specific situation and I'm running into a problem: it's not printing all the levels that I'm specifying. Do you have any insights into why? I can't seem to find any documentation on the cntr.cntr method, so I'm just trial-and-erroring it for now. I'd like it to print more than 6 contour levels (why did you have this limit?), so I changed your error statement. I've also used a 10x10x10 grid, and put in my own data for the 'v' set. Also, I've simplified it so that it's only displaying in the X-Y plane, and so that it's only displaying one "slice" in that plane. I'm asking it to display contours every 0.1, between 3.0 and 4.0, but some contours are missing, and come up as empty arrays when I print 'c'. I've uploaded the modified file. http://old.nabble.com/file/p33197575/cntr3d_alw.py cntr3d_alw.py Thanks! Amanda -- View this message in context: http://old.nabble.com/Plotting-contour-in-X-Z-plane-tp33168965p33197575.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: andi <and...@go...> - 2012-01-24 17:53:24
|
Hi all, I have some old custom code for generating videos from matplotlib (not using the animation module). It used to work, but is now failing. Here is what I am doing: ------------------- import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111) im = ax.imshow(np.zeros((100, 100))) fig.canvas.draw() ax.draw_artist(im) ------------------ ... and draw_artist from axes.py then gives me an AssertionError because no renderer is found (assert self._cachedRenderer is not None). Right now I am using matplotlib 1.0.1 and I think that the above used to work with older versions in matplotlib. See e.g. http://www.mail-archive.com/mat...@li.../msg06598.html Any ideas? Cheers Andi |
|
From: Gousios G. <gg...@wi...> - 2012-01-24 15:20:41
|
Στις 24/01/2012 01:31 μμ, ο/η Gousios George έγραψε: > Στις 23/01/2012 08:39 μμ, ο/η Tony Yu έγραψε: >> >> >> 2012/1/23 Gousios George <gg...@wi... >> <mailto:gg...@wi...>> >> >> Στις 23/01/2012 08:10 μμ, ο/η Benjamin Root έγραψε: >>> 2012/1/23 Gousios George <gg...@wi... >>> <mailto:gg...@wi...>> >>> >>> Στις 23/01/2012 07:48 μμ, ο/η Tony Yu έγραψε: >>>> >>>> >>>> 2012/1/23 Gousios George <gg...@wi... >>>> <mailto:gg...@wi...>> >>>> >>>> Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε: >>>>> >>>>> >>>>> 2012/1/23 Gousios George <gg...@wi... >>>>> <mailto:gg...@wi...>> >>>>> >>>>> Στις 21/01/2012 07:43 μμ, ο/η Gousios George έγραψε: >>>>>> Στις 21/01/2012 07:05 μμ, ο/η Tony Yu έγραψε: >>>>>>> >>>>>>> >>>>>>> On Sat, Jan 21, 2012 at 11:31 AM, Gousios George >>>>>>> <gg...@wi... >>>>>>> <mailto:gg...@wi...>> wrote: >>>>>>> >>>>>>> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε: >>>>>>>> >>>>>>>> >>>>>>>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios >>>>>>>> George <gg...@wi... >>>>>>>> <mailto:gg...@wi...>> wrote: >>>>>>>> >>>>>>>> Hello , i have the following code in >>>>>>>> matlab and trying to do it in >>>>>>>> matplotlib. >>>>>>>> >>>>>>>> I have this code in matlab (in a >>>>>>>> function showGraphs): >>>>>>>> ... >>>>>>>> m = size(myList, 3); >>>>>>>> for k = 1:m >>>>>>>> g = myList(:, :, k); >>>>>>>> image(g + 1) >>>>>>>> axis off >>>>>>>> axis square >>>>>>>> M(k) = getframe; >>>>>>>> end; >>>>>>>> >>>>>>>> and in another file (another function): >>>>>>>> ... >>>>>>>> M = showGraphs(grids) >>>>>>>> movie(M, 1) >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I did so far: >>>>>>>> >>>>>>>> def showGraphs(data): >>>>>>>> data=sc.array([data]) >>>>>>>> n=sc.shape(data)[2] >>>>>>>> for k in range(n): >>>>>>>> mydata=data[:,:,k] >>>>>>>> #plt.imshow(mydata+1) -->> >>>>>>>> this doesn't work >>>>>>>> >>>>>>>> Also ,in order to do the animation : >>>>>>>> >>>>>>>> grids=...(result from another function) >>>>>>>> result=showGraph(grids) >>>>>>>> fig=plt.figure() >>>>>>>> ani=animation.FuncAnimation(fig,result,interval=30,blit=True) >>>>>>>> plt.show() >>>>>>>> >>>>>>>> Right now the program says "TypeError: >>>>>>>> 'NoneType' object is not >>>>>>>> callable" (it has errors in the >>>>>>>> animation call) >>>>>>>> >>>>>>>> What should be my approach to this in >>>>>>>> order to have the animation? >>>>>>>> >>>>>>>> Thank you! >>>>>>>> >>>>>>>> >>>>>>>> You're getting that error because the >>>>>>>> second argument to FuncAnimation (`result` >>>>>>>> in your example) should be a function (not >>>>>>>> always; see example 2 linked below). Right >>>>>>>> now, if your `showGraphs` function is >>>>>>>> defined in full, it returns a value of >>>>>>>> None, which gets saved to `result` (hence >>>>>>>> the error). >>>>>>>> >>>>>>>> You should take a look at some of the image >>>>>>>> animation examples (ex1 >>>>>>>> <http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>, >>>>>>>> ex2 >>>>>>>> <http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>). >>>>>>>> >>>>>>>> -Tony >>>>>>>> >>>>>>> >>>>>>> I did now : >>>>>>> >>>>>>> >>>>>>> def showGraphs(data): >>>>>>> data=sc.array([data]) >>>>>>> n=sc.shape(data)[2] >>>>>>> ims=[] >>>>>>> >>>>>>> for k in range(n): >>>>>>> mydata=data[:,:,k] >>>>>>> im=plt.imshow(mydata+1) >>>>>>> ims.append([im]) >>>>>>> return ims >>>>>>> >>>>>>> and now it gives me "TypeError: Invalid >>>>>>> dimensions for image data. >>>>>>> >>>>>>> >>>>>>> Please post short, but executable examples when >>>>>>> possible. I'm not sure what your data looks >>>>>>> like, but your call to `sc.array` is strange >>>>>>> (I'm not sure why you have square brackets, >>>>>>> which effectively adds an unnecessary dimension >>>>>>> to your data). >>>>>>> >>>>>>> The code attached below should work. >>>>>>> >>>>>>> Cheers, >>>>>>> -Tony >>>>>>> >>>>>>> import numpy as np >>>>>>> import matplotlib.pyplot as plt >>>>>>> from matplotlib.animation import ArtistAnimation >>>>>>> >>>>>>> >>>>>>> fig = plt.figure() >>>>>>> >>>>>>> def showGraphs(data): >>>>>>> data = np.asarray(data) # unnecessary in >>>>>>> this example >>>>>>> n = np.shape(data)[2] >>>>>>> >>>>>>> ims = [] >>>>>>> #for mydata in np.rollaxis(data, -1): >>>>>>> for k in range(n): >>>>>>> mydata = data[:, :, k] >>>>>>> im = plt.imshow(mydata) >>>>>>> ims.append([im]) >>>>>>> return ims >>>>>>> >>>>>>> # 5 frames of a random 20 x 20 image >>>>>>> data = np.random.uniform(size=(20, 20, 5)) >>>>>>> ims = showGraphs(data) >>>>>>> >>>>>>> ani = ArtistAnimation(fig, ims) >>>>>>> plt.show() >>>>>> Now,it gives me 2 figures (why 2?) but >>>>>> empty.(maybe i didn't convert right the matlab >>>>>> code below?) >>>>>> The data in the showGraphs function is the result >>>>>> from this function (in matlab): >>>>>> ......... >>>>>> grids = zeros(n, n, t + 1); >>>>>> grids(:, :, 1) = rest; >>>>>> for i = 2:(t + 1) >>>>>> Extended = extendLat1(rest); >>>>>> rest = applyExtended(Extended); >>>>>> grids(:, :, i) = rest; >>>>>> end; >>>>>> >>>>>> And i did this in python: >>>>>> >>>>>> grids=sc.zeros((area,area,t+1)) >>>>>> rest=grids[:,:,0] >>>>>> for i in range(1,t): >>>>>> extended=extend(rest) >>>>>> rest=apply_extend(extended) >>>>>> grids[:,:,i]=rest >>>>>> return grids >>>>>> >>>>>> Thanks for helping! >>>>>> >>>>> Any help?Thanks! >>>>> >>>>> Sorry, but could you be a bit clearer: >>>>> * Did the example I provide work for you? >>>>> * Assuming it did, are you essentially replacing >>>>> `data` in my example with `grids` in this most recent >>>>> example? >>>>> * I don't get 2 figures: are you asking about the code >>>>> from my last message? >>>>> * Please provide a minimal, *executable* example >>>>> >>>>> -Tony >>>> Ok,i 'll try! >>>> >>>> 1) Yes,your example works fine. >>>> 2) Yes,i return grids from another function (work) doing : >>>> >>>> grids=work(area,...,time) >>>> result=showGraphs(grids) >>>> ani=ArtistAnimation(fig,result) >>>> plt.show() >>>> >>>> The contents of the work function are shown above. >>>> I just want to make sure that i have done the >>>> conversion from matlab right. >>>> Maybe the problem is somewhere else? >>>> >>>> Thank you. >>>> >>>> >>>> Did you get 2 figures with my original example, or just in >>>> your modified code? If it's only in your modified code, >>>> then there's something you're not showing which is creating >>>> the extra figure. >>>> >>>> Unfortunately, the `work` function you showed in the >>>> previous message is not executable (`apply_extend`, >>>> `extend`, etc. aren't defined), which it makes it very >>>> difficult to debug. If my code snippet worked for you, then >>>> the only difference is in how you've defined `grids`---do >>>> you know how it's different? >>>> >>>> -Tony >>>> >>> Ok,i am sending you the whole code of the program. (forget >>> the names of the functions i showed you so far , i use other >>> names). >>> >>> EMPTY=0 #empty cell >>> TREE=1 #tree cell >>> BURNING=2 #burning cell >>> probTree=0.8 #probability of tree >>> probBurning=0.001 #a tree ignites with this probability >>> even if no neighbor is burning >>> probLighting=0.0001 #chance that a tree been hit from light >>> probResistBurn=0.3 #chance that a tree does not burn even >>> if it's neighbor burns >>> t=20 >>> area=50 >>> >>> >>> def spread(cell,N,E,S,W): >>> >>> if cell==EMPTY: >>> return EMPTY >>> elif cell==BURNING: >>> return EMPTY >>> else: >>> if (N==BURNING or E==BURNING or S==BURNING or >>> W==BURNING): >>> if (sc.rand()<probResistBurn): >>> return TREE >>> else: >>> return BURNING >>> elif (sc.rand()<probLighting *(1-probResistBurn)): >>> return BURNING >>> else: >>> return TREE >>> >>> def extend(lat): >>> lat = sc.matrix(lat) >>> extendRows= sc.vstack([lat[-1,:], lat, lat[0,:]]) >>> extendLat=sc.hstack([extendRows[:,-1], extendRows, >>> extendRows[:,0]]) >>> return extendLat >>> >>> def apply_extend(matr): >>> #matr = sc.matrix(matr) >>> matr=sc.array([matr]) >>> area=sc.shape(matr)[0] >>> final=sc.zeros((area,area)) >>> for i in range(1,area): >>> for j in range(1,area): >>> cell=matr[i,j] >>> N=matr[i-1,j] >>> E=matr[i,j+1] >>> S=matr[i+1,j] >>> W=matr[i,j-1] >>> final[i-1,j-1]=spread(cell,N,E,S,W) >>> return final >>> >>> def >>> fire(area,probTree,probBurning,probLighting,probResistBurn,t): >>> >>> trees_or_burns=sc.rand(area,area)<probTree # tree or a >>> burning tree >>> burns=trees_or_burns*(sc.rand(area,area)<probBurning) >>> # burning tree >>> trees=trees_or_burns-burns >>> # tree >>> empties=sc.ones((area,area))-trees_or_burns >>> # empty cell >>> >>> forest=empties*EMPTY + trees*TREE + burns*BURNING #the >>> whole forest >>> >>> grids=sc.zeros((area,area,t+1)) >>> forest=grids[:,:,0] >>> for i in range(1,): >>> extended_forest=extend(forest) >>> forest=apply_extend(extended_forest) >>> grids[:,:,i]=forest >>> return grids >>> >>> def Graph(data): >>> data=sc.array(data) >>> n=sc.shape(data)[2] >>> ims=[] >>> for i in range(n): >>> mydata=data[:,:,i] >>> im=plt.imshow(mydata) >>> >>> ims.append([im]) >>> return ims >>> >>> >>> if __name__=="__main__": >>> >>> grids=fire(area,probTree,probBurning,probLighting,probResistBurn,t) >>> result=Graph(grids) >>> fig=plt.figure() >>> >>> #ani=animation.FuncAnimation(fig,result,interval=30,blit=True,repeat_delay=1000) >>> ani=ArtistAnimation(fig,result) >>> plt.show() >>> >>> Also, i am sending you the code in matlab : >>> >>> >>> >>> In Graph(), you call "plt.imshow()", which will create a new >>> figure automatically if one doesn't exist already. Change >>> fig=plt.figure() to fig=plt.gcf() >>> >>> Ben Root >>> >> Ok,now it shows me only one figure but it's full of blue color >> and doesn't do anything. >> Thanks >> >> Actually, it's plotting your data correctly. If you print out the >> values of `mydata` in the `Graph` loop, you'll see that everything is >> zero. >> >> -Tony > You are right they are all zeros!I don't unsderstand.. > > I am not sure if the function extend causes the problem. > > The extend function from matlab is : > > function extlat = extendLat1(lat); > extendRows = [lat(end, :); lat; lat(1, :)]; > extlat = [extendRows(:, end) extendRows extendRows(:, 1)]; > > I tested my version and i am sure that it gives the right results.But > here,in matlab it has "lat" as argument . In python i create "lat = > sc.matrix(lat)" .I think this is right?? > > Also , the function apply_extend in matlab is: > > function newmat = applyExtended(matExt); > n = size(matExt, 1) - 2; > newmat = zeros(n); > for i = 2:(n + 1) > for j = 2:(n + 1) > site = matExt(i, j); > N = matExt(i - 1, j); > E = matExt(i, j + 1); > S = matExt(i + 1, j); > W = matExt(i, j - 1); > newmat(i - 1, j - 1) = spread(site, N, E, S, W); > end; > end; > > I think i have done it right. > > Also ,the function fire in matlab : > > function grids = fire(n, probTree, probBurning, chanceLightning, > chanceImmune, t); > > global EMPTY TREE BURNING probLightning probImmune > EMPTY = 0; TREE = 1; BURNING = 2; > probLightning = chanceLightning; > probImmune = chanceImmune; > > treesOrBurns = (rand(n) < probTree); > > burns = treesOrBurns .* (rand(n) < probBurning); > > trees = treesOrBurns - burns; > > empties = 1 - treesOrBurns; > > forest = empties * EMPTY + trees * TREE + burns * BURNING; > > grids = zeros(n, n, t + 1); > grids(:, :, 1) = forest; > for i = 2:(t + 1) > forestExtended = extendLat1(forest); > forest = applyExtended(forestExtended); > grids(:, :, i) = forest; > end; > > > Could someone figure where am i doing wrong?(i have the whole code of > mine above). > > Thanks! > Ok, i figured the error! It was at the "forest=grids[:,:,0]".It should be "grids[:,:,0]=forest". Now i want to ask 2 questions. 1) How to stop the animation??It should stop when the simulation ends but now it starts all over again. 2) How to use colormaps ,because i didn't understand from here <http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps> or here <http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps>. And how can i put specific colors for specific values.For example for my value "EMPTY->color white",TREE->color green. Thank you! |
|
From: John H. <jd...@gm...> - 2012-01-24 13:02:53
|
On Jan 24, 2012, at 6:06 AM, Piter_ <x....@gm...> wrote: > Hi all. > Hi all. Can I open matlab figure in matplotlib without conversion in > any other format? > I am 90% sure the answer for my question if not. But I give a 10% lazy > hope that it is possible. No, and there are no plans to support it. We want to provide a fairly easy mental map for people familiar with matlab to use matplotlib, but don't expend any effort on full compatibility, eg running m-files and opening fig files. For that degree of compatibility, there is matlab itself and octave. JDH |
|
From: Piter_ <x....@gm...> - 2012-01-24 12:06:29
|
Hi all. Hi all. Can I open matlab figure in matplotlib without conversion in any other format? I am 90% sure the answer for my question if not. But I give a 10% lazy hope that it is possible. Thanks |
|
From: Gousios G. <gg...@wi...> - 2012-01-24 11:32:07
|
Στις 23/01/2012 08:39 μμ, ο/η Tony Yu έγραψε: > > > 2012/1/23 Gousios George <gg...@wi... > <mailto:gg...@wi...>> > > Στις 23/01/2012 08:10 μμ, ο/η Benjamin Root έγραψε: >> 2012/1/23 Gousios George <gg...@wi... >> <mailto:gg...@wi...>> >> >> Στις 23/01/2012 07:48 μμ, ο/η Tony Yu έγραψε: >>> >>> >>> 2012/1/23 Gousios George <gg...@wi... >>> <mailto:gg...@wi...>> >>> >>> Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε: >>>> >>>> >>>> 2012/1/23 Gousios George <gg...@wi... >>>> <mailto:gg...@wi...>> >>>> >>>> Στις 21/01/2012 07:43 μμ, ο/η Gousios George έγραψε: >>>>> Στις 21/01/2012 07:05 μμ, ο/η Tony Yu έγραψε: >>>>>> >>>>>> >>>>>> On Sat, Jan 21, 2012 at 11:31 AM, Gousios George >>>>>> <gg...@wi... >>>>>> <mailto:gg...@wi...>> wrote: >>>>>> >>>>>> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε: >>>>>>> >>>>>>> >>>>>>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios >>>>>>> George <gg...@wi... >>>>>>> <mailto:gg...@wi...>> wrote: >>>>>>> >>>>>>> Hello , i have the following code in >>>>>>> matlab and trying to do it in >>>>>>> matplotlib. >>>>>>> >>>>>>> I have this code in matlab (in a >>>>>>> function showGraphs): >>>>>>> ... >>>>>>> m = size(myList, 3); >>>>>>> for k = 1:m >>>>>>> g = myList(:, :, k); >>>>>>> image(g + 1) >>>>>>> axis off >>>>>>> axis square >>>>>>> M(k) = getframe; >>>>>>> end; >>>>>>> >>>>>>> and in another file (another function): >>>>>>> ... >>>>>>> M = showGraphs(grids) >>>>>>> movie(M, 1) >>>>>>> >>>>>>> >>>>>>> >>>>>>> I did so far: >>>>>>> >>>>>>> def showGraphs(data): >>>>>>> data=sc.array([data]) >>>>>>> n=sc.shape(data)[2] >>>>>>> for k in range(n): >>>>>>> mydata=data[:,:,k] >>>>>>> #plt.imshow(mydata+1) -->> >>>>>>> this doesn't work >>>>>>> >>>>>>> Also ,in order to do the animation : >>>>>>> >>>>>>> grids=...(result from another function) >>>>>>> result=showGraph(grids) >>>>>>> fig=plt.figure() >>>>>>> ani=animation.FuncAnimation(fig,result,interval=30,blit=True) >>>>>>> plt.show() >>>>>>> >>>>>>> Right now the program says "TypeError: >>>>>>> 'NoneType' object is not >>>>>>> callable" (it has errors in the >>>>>>> animation call) >>>>>>> >>>>>>> What should be my approach to this in >>>>>>> order to have the animation? >>>>>>> >>>>>>> Thank you! >>>>>>> >>>>>>> >>>>>>> You're getting that error because the second >>>>>>> argument to FuncAnimation (`result` in your >>>>>>> example) should be a function (not always; >>>>>>> see example 2 linked below). Right now, if >>>>>>> your `showGraphs` function is defined in >>>>>>> full, it returns a value of None, which gets >>>>>>> saved to `result` (hence the error). >>>>>>> >>>>>>> You should take a look at some of the image >>>>>>> animation examples (ex1 >>>>>>> <http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>, >>>>>>> ex2 >>>>>>> <http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>). >>>>>>> >>>>>>> -Tony >>>>>>> >>>>>> >>>>>> I did now : >>>>>> >>>>>> >>>>>> def showGraphs(data): >>>>>> data=sc.array([data]) >>>>>> n=sc.shape(data)[2] >>>>>> ims=[] >>>>>> >>>>>> for k in range(n): >>>>>> mydata=data[:,:,k] >>>>>> im=plt.imshow(mydata+1) >>>>>> ims.append([im]) >>>>>> return ims >>>>>> >>>>>> and now it gives me "TypeError: Invalid >>>>>> dimensions for image data. >>>>>> >>>>>> >>>>>> Please post short, but executable examples when >>>>>> possible. I'm not sure what your data looks like, >>>>>> but your call to `sc.array` is strange (I'm not >>>>>> sure why you have square brackets, which >>>>>> effectively adds an unnecessary dimension to your >>>>>> data). >>>>>> >>>>>> The code attached below should work. >>>>>> >>>>>> Cheers, >>>>>> -Tony >>>>>> >>>>>> import numpy as np >>>>>> import matplotlib.pyplot as plt >>>>>> from matplotlib.animation import ArtistAnimation >>>>>> >>>>>> >>>>>> fig = plt.figure() >>>>>> >>>>>> def showGraphs(data): >>>>>> data = np.asarray(data) # unnecessary in this >>>>>> example >>>>>> n = np.shape(data)[2] >>>>>> >>>>>> ims = [] >>>>>> #for mydata in np.rollaxis(data, -1): >>>>>> for k in range(n): >>>>>> mydata = data[:, :, k] >>>>>> im = plt.imshow(mydata) >>>>>> ims.append([im]) >>>>>> return ims >>>>>> >>>>>> # 5 frames of a random 20 x 20 image >>>>>> data = np.random.uniform(size=(20, 20, 5)) >>>>>> ims = showGraphs(data) >>>>>> >>>>>> ani = ArtistAnimation(fig, ims) >>>>>> plt.show() >>>>> Now,it gives me 2 figures (why 2?) but >>>>> empty.(maybe i didn't convert right the matlab >>>>> code below?) >>>>> The data in the showGraphs function is the result >>>>> from this function (in matlab): >>>>> ......... >>>>> grids = zeros(n, n, t + 1); >>>>> grids(:, :, 1) = rest; >>>>> for i = 2:(t + 1) >>>>> Extended = extendLat1(rest); >>>>> rest = applyExtended(Extended); >>>>> grids(:, :, i) = rest; >>>>> end; >>>>> >>>>> And i did this in python: >>>>> >>>>> grids=sc.zeros((area,area,t+1)) >>>>> rest=grids[:,:,0] >>>>> for i in range(1,t): >>>>> extended=extend(rest) >>>>> rest=apply_extend(extended) >>>>> grids[:,:,i]=rest >>>>> return grids >>>>> >>>>> Thanks for helping! >>>>> >>>> Any help?Thanks! >>>> >>>> Sorry, but could you be a bit clearer: >>>> * Did the example I provide work for you? >>>> * Assuming it did, are you essentially replacing `data` >>>> in my example with `grids` in this most recent example? >>>> * I don't get 2 figures: are you asking about the code >>>> from my last message? >>>> * Please provide a minimal, *executable* example >>>> >>>> -Tony >>> Ok,i 'll try! >>> >>> 1) Yes,your example works fine. >>> 2) Yes,i return grids from another function (work) doing : >>> >>> grids=work(area,...,time) >>> result=showGraphs(grids) >>> ani=ArtistAnimation(fig,result) >>> plt.show() >>> >>> The contents of the work function are shown above. >>> I just want to make sure that i have done the conversion >>> from matlab right. >>> Maybe the problem is somewhere else? >>> >>> Thank you. >>> >>> >>> Did you get 2 figures with my original example, or just in >>> your modified code? If it's only in your modified code, then >>> there's something you're not showing which is creating the >>> extra figure. >>> >>> Unfortunately, the `work` function you showed in the >>> previous message is not executable (`apply_extend`, >>> `extend`, etc. aren't defined), which it makes it very >>> difficult to debug. If my code snippet worked for you, then >>> the only difference is in how you've defined `grids`---do >>> you know how it's different? >>> >>> -Tony >>> >> Ok,i am sending you the whole code of the program. (forget >> the names of the functions i showed you so far , i use other >> names). >> >> EMPTY=0 #empty cell >> TREE=1 #tree cell >> BURNING=2 #burning cell >> probTree=0.8 #probability of tree >> probBurning=0.001 #a tree ignites with this probability even >> if no neighbor is burning >> probLighting=0.0001 #chance that a tree been hit from light >> probResistBurn=0.3 #chance that a tree does not burn even >> if it's neighbor burns >> t=20 >> area=50 >> >> >> def spread(cell,N,E,S,W): >> >> if cell==EMPTY: >> return EMPTY >> elif cell==BURNING: >> return EMPTY >> else: >> if (N==BURNING or E==BURNING or S==BURNING or >> W==BURNING): >> if (sc.rand()<probResistBurn): >> return TREE >> else: >> return BURNING >> elif (sc.rand()<probLighting *(1-probResistBurn)): >> return BURNING >> else: >> return TREE >> >> def extend(lat): >> lat = sc.matrix(lat) >> extendRows= sc.vstack([lat[-1,:], lat, lat[0,:]]) >> extendLat=sc.hstack([extendRows[:,-1], extendRows, >> extendRows[:,0]]) >> return extendLat >> >> def apply_extend(matr): >> #matr = sc.matrix(matr) >> matr=sc.array([matr]) >> area=sc.shape(matr)[0] >> final=sc.zeros((area,area)) >> for i in range(1,area): >> for j in range(1,area): >> cell=matr[i,j] >> N=matr[i-1,j] >> E=matr[i,j+1] >> S=matr[i+1,j] >> W=matr[i,j-1] >> final[i-1,j-1]=spread(cell,N,E,S,W) >> return final >> >> def >> fire(area,probTree,probBurning,probLighting,probResistBurn,t): >> >> trees_or_burns=sc.rand(area,area)<probTree # tree or a >> burning tree >> burns=trees_or_burns*(sc.rand(area,area)<probBurning) >> # burning tree >> trees=trees_or_burns-burns # >> tree >> empties=sc.ones((area,area))-trees_or_burns # >> empty cell >> >> forest=empties*EMPTY + trees*TREE + burns*BURNING #the >> whole forest >> >> grids=sc.zeros((area,area,t+1)) >> forest=grids[:,:,0] >> for i in range(1,): >> extended_forest=extend(forest) >> forest=apply_extend(extended_forest) >> grids[:,:,i]=forest >> return grids >> >> def Graph(data): >> data=sc.array(data) >> n=sc.shape(data)[2] >> ims=[] >> for i in range(n): >> mydata=data[:,:,i] >> im=plt.imshow(mydata) >> >> ims.append([im]) >> return ims >> >> >> if __name__=="__main__": >> >> grids=fire(area,probTree,probBurning,probLighting,probResistBurn,t) >> result=Graph(grids) >> fig=plt.figure() >> >> #ani=animation.FuncAnimation(fig,result,interval=30,blit=True,repeat_delay=1000) >> ani=ArtistAnimation(fig,result) >> plt.show() >> >> Also, i am sending you the code in matlab : >> >> >> >> In Graph(), you call "plt.imshow()", which will create a new >> figure automatically if one doesn't exist already. Change >> fig=plt.figure() to fig=plt.gcf() >> >> Ben Root >> > Ok,now it shows me only one figure but it's full of blue color and > doesn't do anything. > Thanks > > Actually, it's plotting your data correctly. If you print out the > values of `mydata` in the `Graph` loop, you'll see that everything is > zero. > > -Tony You are right they are all zeros!I don't unsderstand.. I am not sure if the function extend causes the problem. The extend function from matlab is : function extlat = extendLat1(lat); extendRows = [lat(end, :); lat; lat(1, :)]; extlat = [extendRows(:, end) extendRows extendRows(:, 1)]; I tested my version and i am sure that it gives the right results.But here,in matlab it has "lat" as argument . In python i create "lat = sc.matrix(lat)" .I think this is right?? Also , the function apply_extend in matlab is: function newmat = applyExtended(matExt); n = size(matExt, 1) - 2; newmat = zeros(n); for i = 2:(n + 1) for j = 2:(n + 1) site = matExt(i, j); N = matExt(i - 1, j); E = matExt(i, j + 1); S = matExt(i + 1, j); W = matExt(i, j - 1); newmat(i - 1, j - 1) = spread(site, N, E, S, W); end; end; I think i have done it right. Also ,the function fire in matlab : function grids = fire(n, probTree, probBurning, chanceLightning, chanceImmune, t); global EMPTY TREE BURNING probLightning probImmune EMPTY = 0; TREE = 1; BURNING = 2; probLightning = chanceLightning; probImmune = chanceImmune; treesOrBurns = (rand(n) < probTree); burns = treesOrBurns .* (rand(n) < probBurning); trees = treesOrBurns - burns; empties = 1 - treesOrBurns; forest = empties * EMPTY + trees * TREE + burns * BURNING; grids = zeros(n, n, t + 1); grids(:, :, 1) = forest; for i = 2:(t + 1) forestExtended = extendLat1(forest); forest = applyExtended(forestExtended); grids(:, :, i) = forest; end; Could someone figure where am i doing wrong?(i have the whole code of mine above). Thanks! |
|
From: Benjamin R. <ben...@ou...> - 2012-01-24 02:54:47
|
On Monday, January 23, 2012, Álvaro Justen [Turicas] <alv...@gm...> wrote: > Hello, > I'm using version 1.0.1 and I think this code snippet and the images > attached are enough to explain the bug: > https://gist.github.com/1667300 > > Images 'bar-log-bug.png' and 'bar-log-ok.png' must be the same since > it is the same data and same configuration - the bug occurs when we > call set_yscale after calling subplot.bar(). > > If you confirm the bug, I'll create an issue on GitHub. This is a known issue and is not a bug. If you know that you are using log scale for your bar graph, then it is best to simply specify it in the bar() command (log=True, I think). Having bar() work when you call set_yscale() before bar() is merely a convenience. Recommended usage is to tell bar() that you are using log scale so that it can avoid taking the log of zero (or negative). Cheers, Ben Root |
|
From: Álvaro J. [T. <alv...@gm...> - 2012-01-24 01:57:38
|
Hello, I'm using version 1.0.1 and I think this code snippet and the images attached are enough to explain the bug: https://gist.github.com/1667300 Images 'bar-log-bug.png' and 'bar-log-ok.png' must be the same since it is the same data and same configuration - the bug occurs when we call set_yscale after calling subplot.bar(). If you confirm the bug, I'll create an issue on GitHub. Thanks, -- Álvaro Justen "Turicas" http://blog.justen.eng.br http://twitter.com/turicas http://CursoDeArduino.com.br http://github.com/turicas +55 21 9898-0141 |