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: Paul I. <piv...@gm...> - 2012-01-23 21:20:05
|
Paul Ivanov, on 2012-01-23 13:07, wrote: > the quick and dirty way to get close to what you want is to add > an alpha value to the lines you're already plotting. Here's a > small example: > > x = np.arange(0,3,.01) > y = np.sin(x**2) > all_x,all_y = [],[] > ax = plt.gca() > for i in range(100): > noisex = np.random.randn(1)*.04 > noisey = (np.random.randn(x.shape[0])*.2)**3 > ax.plot(x+noisex,y+noisey, color='b', alpha=.01) > all_x.append(x+noisex) > all_y.append(y+noisey) > > To get a heat diagram, as was suggested, you can use a 2d > histogram. > > plt.figure() > all_x =np.array(all_x) > all_y = np.array(all_y) > all_x.shape = all_y.shape = -1 > H, yedges, xedges = np.histogram2d(all_y, all_x, bins=100) > extent = [xedges[0], xedges[-1], yedges[-1], yedges[0]] > ax = plt.gca() > plt.hot() > ax.imshow(H, extent=extent, interpolation='nearest') > ax.invert_yaxis() For completeness, attached is what the hexbin version of the same data looks like: plt.hexbin(all_x, all_y) You may want to play with the 'bins' (for histogram2d) and 'griddata' (for hexbin) parameters to get the appropriate level of detail for the amount of data you have. best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |
|
From: Paul I. <piv...@gm...> - 2012-01-23 21:08:03
|
Hi Russ, Russ Dill, on 2012-01-21 13:30, wrote: > I'm using matplotlib from pylab to generate eye patterns for signal > simulations. My output pretty much looks like this: > > http://www.flickr.com/photos/31208937@N06/6079131690/ > > Its pretty useful as it allows one to quickly see the size of the eye > opening, the maximum/minimum voltage, etc. I'd really like to be able > to create a heat diagram, like these: > > http://www.lecroy.com/images/oscilloscope/series/waveexpert/opening-spread2_lg.jpg > http://www.lecroy.com/images/oscilloscope/series/waveexpert/opening-spread1_lg.jpg > http://www.iec.org/newsletter/august07_2/imgs/bb2_fig_1.gif > http://www.altera.com/devices/fpga/stratix-fpgas/stratix-ii/stratix-ii-gx/images/s2gx-rollout-6g-eye.jpg > > Is there any way within matplotlib to do that right now? the quick and dirty way to get close to what you want is to add an alpha value to the lines you're already plotting. Here's a small example: x = np.arange(0,3,.01) y = np.sin(x**2) all_x,all_y = [],[] ax = plt.gca() for i in range(100): noisex = np.random.randn(1)*.04 noisey = (np.random.randn(x.shape[0])*.2)**3 ax.plot(x+noisex,y+noisey, color='b', alpha=.01) all_x.append(x+noisex) all_y.append(y+noisey) To get a heat diagram, as was suggested, you can use a 2d histogram. plt.figure() all_x =np.array(all_x) all_y = np.array(all_y) all_x.shape = all_y.shape = -1 H, yedges, xedges = np.histogram2d(all_y, all_x, bins=100) extent = [xedges[0], xedges[-1], yedges[-1], yedges[0]] ax = plt.gca() plt.hot() ax.imshow(H, extent=extent, interpolation='nearest') ax.invert_yaxis() I'm attaching the two images for reference best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |
|
From: Benjamin R. <ben...@ou...> - 2012-01-23 20:35:35
|
On Mon, Jan 23, 2012 at 2:21 PM, Tony Yu <ts...@gm...> wrote: > > > On Mon, Jan 23, 2012 at 2:43 PM, reckoner <rec...@gm...> wrote: > >> Hi, >> >> I am trying to create a sequence of rotated rectangles of various >> sizes/orientations. I have been looking at the following page: >> >> http://matplotlib.sourceforge.net/devel/transformations.html >> >> But I can't find any examples of how to use these transformations and >> then show the resulting figures. I am trying to create a sequence of >> frames for a rectangle tumbling forward. This means I would need to >> daisychain the transformations noted above. >> >> Any help getting started would be greatly appreciated! >> >> > Have you seen the Transformations Tutorial<http://matplotlib.sourceforge.net/users/transforms_tutorial.html>? > It has a number of usage examples. > > Cheers, > -Tony > > Do note that while I think what you want to do is techinically feasible, the Transformation framework is probably not really intended for this purpose and may feel awkward. That being said, I think that this example may be the closest to what you want to do: http://matplotlib.sourceforge.net/users/transforms_tutorial.html#using-offset-transforms-to-create-a-shadow-effect Cheers! Ben Root |
|
From: Benjamin R. <ben...@ou...> - 2012-01-23 20:31:10
|
On Mon, Jan 23, 2012 at 1:46 PM, Ethan Swint <es...@vt...> wrote: > > > On 1/23/2012 1:55 PM, Russ Dill wrote: > > On Mon, Jan 23, 2012 at 11:17 AM, Stan West<sta...@nr...> > wrote: > >>> From: Russ Dill [mailto:rus...@gm...] > >>> Sent: Saturday, January 21, 2012 16:31 > >>> > >>> I'm using matplotlib from pylab to generate eye patterns for signal > >>> simulations. > >> ... > >> > >>> Is there any way within matplotlib to do that right now? > >> One way combines Numpy's histogram2d and matplotlib's imshow, as in the > >> example in the histogram2d docs [1]. The example's x array should > become all > >> of the time samples in your traces, strung together in one dimension; > the y > >> array, the corresponding voltage samples. > >> > > I'll try it out and see what I get, but I don't think it will work so > > well. The problem is that while the data is made up of x/y samples, it > > actually represents a line. The samples should be evenly distributed > > not along the x or y axis, but along the length of the line. I feel > > like I'll need a line drawing algorithm. > > > > (For example, if samples are evenly distributed along the x axis, a 89 > > degree line is highly under-represented, but a 1 degree line is highly > > over-represented. The number of samples should be sqrt(dx^2 + dy^2), > > but with evenly spaced x samples, its just dx. > > I don't know of a way to directly produce the LeCroy heatmap in Python, > so here's my idea for a hack: > *Each sample point you have from the trace represents a point in XY > coordinates. > *Similarly, the plot area is filled with regularly spaced XY coordinates. > *Every trace sample will fall within a square bounding box with four > points. > *Each plot area point gets a membership value, based on distance between > centers of the sample point and the plot area point. > *To construct the heat diagram, sum the membership values of all sample > points for all traces. > *Display it with a contour plot, but without the isovalue lines. > > -Ethan > > matplotlib also has hexbin() if that helps. http://matplotlib.sourceforge.net/api/axes_api.html?highlight=hexbin#matplotlib.axes.Axes.hexbin Ben Root |
|
From: Tony Yu <ts...@gm...> - 2012-01-23 20:21:13
|
On Mon, Jan 23, 2012 at 2:43 PM, reckoner <rec...@gm...> wrote: > Hi, > > I am trying to create a sequence of rotated rectangles of various > sizes/orientations. I have been looking at the following page: > > http://matplotlib.sourceforge.net/devel/transformations.html > > But I can't find any examples of how to use these transformations and > then show the resulting figures. I am trying to create a sequence of > frames for a rectangle tumbling forward. This means I would need to > daisychain the transformations noted above. > > Any help getting started would be greatly appreciated! > > Have you seen the Transformations Tutorial<http://matplotlib.sourceforge.net/users/transforms_tutorial.html>? It has a number of usage examples. Cheers, -Tony |
|
From: Ethan S. <es...@vt...> - 2012-01-23 19:46:32
|
On 1/23/2012 1:55 PM, Russ Dill wrote: > On Mon, Jan 23, 2012 at 11:17 AM, Stan West<sta...@nr...> wrote: >>> From: Russ Dill [mailto:rus...@gm...] >>> Sent: Saturday, January 21, 2012 16:31 >>> >>> I'm using matplotlib from pylab to generate eye patterns for signal >>> simulations. >> ... >> >>> Is there any way within matplotlib to do that right now? >> One way combines Numpy's histogram2d and matplotlib's imshow, as in the >> example in the histogram2d docs [1]. The example's x array should become all >> of the time samples in your traces, strung together in one dimension; the y >> array, the corresponding voltage samples. >> > I'll try it out and see what I get, but I don't think it will work so > well. The problem is that while the data is made up of x/y samples, it > actually represents a line. The samples should be evenly distributed > not along the x or y axis, but along the length of the line. I feel > like I'll need a line drawing algorithm. > > (For example, if samples are evenly distributed along the x axis, a 89 > degree line is highly under-represented, but a 1 degree line is highly > over-represented. The number of samples should be sqrt(dx^2 + dy^2), > but with evenly spaced x samples, its just dx. I don't know of a way to directly produce the LeCroy heatmap in Python, so here's my idea for a hack: *Each sample point you have from the trace represents a point in XY coordinates. *Similarly, the plot area is filled with regularly spaced XY coordinates. *Every trace sample will fall within a square bounding box with four points. *Each plot area point gets a membership value, based on distance between centers of the sample point and the plot area point. *To construct the heat diagram, sum the membership values of all sample points for all traces. *Display it with a contour plot, but without the isovalue lines. -Ethan |
|
From: reckoner <rec...@gm...> - 2012-01-23 19:43:27
|
Hi, I am trying to create a sequence of rotated rectangles of various sizes/orientations. I have been looking at the following page: http://matplotlib.sourceforge.net/devel/transformations.html But I can't find any examples of how to use these transformations and then show the resulting figures. I am trying to create a sequence of frames for a rectangle tumbling forward. This means I would need to daisychain the transformations noted above. Any help getting started would be greatly appreciated! |
|
From: Russ D. <rus...@gm...> - 2012-01-23 18:55:58
|
On Mon, Jan 23, 2012 at 11:17 AM, Stan West <sta...@nr...> wrote: >> From: Russ Dill [mailto:rus...@gm...] >> Sent: Saturday, January 21, 2012 16:31 >> >> I'm using matplotlib from pylab to generate eye patterns for signal >> simulations. > > ... > >> Is there any way within matplotlib to do that right now? > > One way combines Numpy's histogram2d and matplotlib's imshow, as in the > example in the histogram2d docs [1]. The example's x array should become all > of the time samples in your traces, strung together in one dimension; the y > array, the corresponding voltage samples. > I'll try it out and see what I get, but I don't think it will work so well. The problem is that while the data is made up of x/y samples, it actually represents a line. The samples should be evenly distributed not along the x or y axis, but along the length of the line. I feel like I'll need a line drawing algorithm. (For example, if samples are evenly distributed along the x axis, a 89 degree line is highly under-represented, but a 1 degree line is highly over-represented. The number of samples should be sqrt(dx^2 + dy^2), but with evenly spaced x samples, its just dx. |
|
From: Tony Yu <ts...@gm...> - 2012-01-23 18:39:45
|
2012/1/23 Gousios George <gg...@wi...> > ** > Στις 23/01/2012 08:10 μμ, ο/η Benjamin Root έγραψε: > > 2012/1/23 Gousios George <gg...@wi...> > >> Στις 23/01/2012 07:48 μμ, ο/η Tony Yu έγραψε: >> >> >> >> 2012/1/23 Gousios George <gg...@wi...> >> >>> Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε: >>> >>> >>> >>> 2012/1/23 Gousios George <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... >>>> > wrote: >>>> >>>>> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε: >>>>> >>>>> >>>>> >>>>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George <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 |
|
From: Stan W. <sta...@nr...> - 2012-01-23 18:31:59
|
> From: Russ Dill [mailto:rus...@gm...] > Sent: Saturday, January 21, 2012 16:31 > > I'm using matplotlib from pylab to generate eye patterns for signal > simulations. ... > Is there any way within matplotlib to do that right now? One way combines Numpy's histogram2d and matplotlib's imshow, as in the example in the histogram2d docs [1]. The example's x array should become all of the time samples in your traces, strung together in one dimension; the y array, the corresponding voltage samples. If you have certain structure, such as a regular and consistent grid of times, you might instead construct a series of vertical, 1-d histograms (paying attention to normalization); column-stack them into the final 2-d histogram; and again plot with imshow. [1] http://docs.scipy.org/doc/numpy-1.6.0/reference/generated/numpy.histogram2d.ht ml |
|
From: Gousios G. <gg...@wi...> - 2012-01-23 18:16:48
|
Στις 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 |
|
From: Benjamin R. <ben...@ou...> - 2012-01-23 18:11:10
|
2012/1/23 Gousios George <gg...@wi...> > ** > Στις 23/01/2012 07:48 μμ, ο/η Tony Yu έγραψε: > > > > 2012/1/23 Gousios George <gg...@wi...> > >> Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε: >> >> >> >> 2012/1/23 Gousios George <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...>wrote: >>> >>>> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε: >>>> >>>> >>>> >>>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George <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 |
|
From: Gousios G. <gg...@wi...> - 2012-01-23 18:05:41
|
Στις 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 : |
|
From: MQMQ <maq...@ho...> - 2012-01-23 17:54:52
|
Thank you so much, I will follow your advice.:) MQ MQMQ wrote: > > Dear all, > > Could you guys share your experience on: > How to adjust the size and scale of the x-y axis of the plot (e.g. how to > resize the "0 1 2" on x axis ), Thanks? > And special commands in matplotlib? > > Thank you so much in advanced. > MQMQ > -- View this message in context: http://old.nabble.com/MQMQ%3A-How-to-adjust-the-size-and-scale-of-the-x-y-axis-of-the-graph.Thanks.-tp33177496p33189796.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
|
From: Tony Yu <ts...@gm...> - 2012-01-23 17:48:36
|
2012/1/23 Gousios George <gg...@wi...> > ** > Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε: > > > > 2012/1/23 Gousios George <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...>wrote: >> >>> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε: >>> >>> >>> >>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George <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 |
|
From: Gousios G. <gg...@wi...> - 2012-01-23 17:12:37
|
Στις 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. |
|
From: Moore, E. (NIH/N. [F] <eri...@ni...> - 2012-01-23 16:58:20
|
From: ben...@gm... [mailto:ben...@gm...] On Behalf Of Benjamin Root Sent: Monday, January 23, 2012 10:49 AM To: Moore, Eric (NIH/NIDDK) [F] Cc: mat...@li... Subject: Re: [Matplotlib-users] Plotting contour in X-Z plane On Thu, Jan 19, 2012 at 12:01 PM, Moore, Eric (NIH/NIDDK) [F] <eri...@ni...<mailto:eri...@ni...>> wrote: > -----Original Message----- > From: alw46 [mailto:ama...@gm...<mailto:ama...@gm...>] > Sent: Thursday, January 19, 2012 11:31 AM > To: mat...@li...<mailto:mat...@li...> > Subject: [Matplotlib-users] Plotting contour in X-Z plane > > > Hi All, > > I have a question similar to one posted on Aug 30, 2011 titled > "Plotting 2D > contourf in Axes3D X-Z plane instead of X-Y plane". In fact, it is the > same > question, and I can't seem to find a satisfactory answer anywhere. > > I've attached an image of what I've done in the X-Y plane for > reference. > Like the other post, I'd like to do something similar to what I've done > in > the X-Y direction, but in the X-Z and Y-Z planes. Since I've set up a > grid > of points throughout the space, this effectively allows me to take > "section > cuts" in different directions in the space. But I can't seem to figure > out > how to do it. I've switched around the "z-dir", as well as replacing X > and > Y with Z in ax.contourf. For reference, I'm using matplotlib 1.1.0. > > I'm trying to achieve a similar affect to Mayavi's 'image_plane_widget' > to > take volume slices, but using matplotlib. > > http://old.nabble.com/file/p33168965/contours_xy.png > -- > View this message in context: http://old.nabble.com/Plotting-contour- > in-X-Z-plane-tp33168965p33168965.html > Sent from the matplotlib - users mailing list archive at Nabble.com. > I've attached a function that I think does something similar to what you want, although without quite all of the bells and whistles you're looking for. I'm sure there are better ways than just plotting so many lines, but it worked for quickly looking at some data for me. Eric Eric, That is a neat example. Do you mind if I clean it up and include it in the mpl gallary? Ben Root Ben, I don't mind. Please feel free to do so. Eric |
|
From: Tony Yu <ts...@gm...> - 2012-01-23 16:52:22
|
2012/1/23 Gousios George <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...>wrote: > >> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε: >> >> >> >> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George <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 |
|
From: Gousios G. <gg...@wi...> - 2012-01-23 16:41:28
|
Στις 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! |
|
From: Tony Yu <ts...@gm...> - 2012-01-23 16:07:24
|
On Mon, Jan 23, 2012 at 9:56 AM, Michael Droettboom <md...@st...> wrote: > I have a solution for this in this pull request: > > https://github.com/matplotlib/matplotlib/pull/684 > > If able, would you mind confirming that it addresses your issue? > > Mike > > This fix worked on my system. -Tony > > On 01/23/2012 09:02 AM, Bruno Santos wrote: > > Sorry it took me a while to get back to you. I have finally written some > code to replicate the problem. I have attached a file with it. > > Thank you very much in advance, > Bruno Santos > > 2012/1/19 Tony Yu <ts...@gm...> > >> >> >> On Thu, Jan 19, 2012 at 12:07 PM, Bruno Santos <bac...@gm...>wrote: >> >>> Hello everyone, >>> >>> I have been using matplotlib 0.99.3 to write some down. But I had to >>> upgrade my OS and so installed the last version of the library 1.1.0. But >>> unfortunately when I try to run my code I get the following error: >>> raise ValueError, 'Path lacks initial MOVETO' >>> ValueError: Path lacks initial MOVETO >>> >>> I have been goggling it and saw some reports about it when using a >>> vector containing zeros for which I apply a log and then trying to plot >>> this. But the reports seem to indicate this was fixed in a svn version I >>> can't access anymore. >>> Can anyone point me on the correct direction to solve this problem? >>> >>> Thank you very much in advance, >>> Bruno Santos >>> >>> Could you provide a bit more information: Are you calling `Path` >> directly? If not, do you know what in your code is calling it? A minimal, >> runnable example would be very helpful. >> >> Cheers, >> -Tony >> >> > > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now!http://p.sf.net/sfu/learndevnow-dev2 > > > > _______________________________________________ > Matplotlib-users mailing lis...@li...://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-dev2 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |
|
From: Benjamin R. <ben...@ou...> - 2012-01-23 15:49:02
|
On Thu, Jan 19, 2012 at 12:01 PM, Moore, Eric (NIH/NIDDK) [F] < eri...@ni...> wrote: > > -----Original Message----- > > From: alw46 [mailto:ama...@gm...] > > Sent: Thursday, January 19, 2012 11:31 AM > > To: mat...@li... > > Subject: [Matplotlib-users] Plotting contour in X-Z plane > > > > > > Hi All, > > > > I have a question similar to one posted on Aug 30, 2011 titled > > "Plotting 2D > > contourf in Axes3D X-Z plane instead of X-Y plane". In fact, it is the > > same > > question, and I can't seem to find a satisfactory answer anywhere. > > > > I've attached an image of what I've done in the X-Y plane for > > reference. > > Like the other post, I'd like to do something similar to what I've done > > in > > the X-Y direction, but in the X-Z and Y-Z planes. Since I've set up a > > grid > > of points throughout the space, this effectively allows me to take > > "section > > cuts" in different directions in the space. But I can't seem to figure > > out > > how to do it. I've switched around the "z-dir", as well as replacing X > > and > > Y with Z in ax.contourf. For reference, I'm using matplotlib 1.1.0. > > > > I'm trying to achieve a similar affect to Mayavi's 'image_plane_widget' > > to > > take volume slices, but using matplotlib. > > > > http://old.nabble.com/file/p33168965/contours_xy.png > > -- > > View this message in context: http://old.nabble.com/Plotting-contour- > > in-X-Z-plane-tp33168965p33168965.html > > Sent from the matplotlib - users mailing list archive at Nabble.com. > > > > I've attached a function that I think does something similar to what you > want, although without quite all of the bells and whistles you're looking > for. I'm sure there are better ways than just plotting so many lines, but > it worked for quickly looking at some data for me. > > Eric > > Eric, That is a neat example. Do you mind if I clean it up and include it in the mpl gallary? Ben Root |
|
From: Ethan S. <es...@vt...> - 2012-01-23 15:03:38
|
On 1/20/2012 5:31 PM, MQMQ wrote: > Dear all, > > Could you guys share your experience on: > How to adjust the size and scale of the x-y axis of the plot (e.g. how to > resize the "0 1 2" on x axis ), Thanks? > And special commands in matplotlib? > > Thank you so much in advanced. > MQMQ You can change the font sizes for most of the plotting elements with the pyplot variable pyplot.rcParams. Change the range of the XY axes by calling pypolt.xlim(0,360) pyplot.ylim(-0.01,4.05) -or- pyplot.axis(0,360,-0.01,4.05) and you can adjust the ticmark values by pyplot.xticks(range(360)) Also look into the pyplot.setp method. -Ethan |
|
From: Michael D. <md...@st...> - 2012-01-23 14:56:34
|
I have a solution for this in this pull request: https://github.com/matplotlib/matplotlib/pull/684 If able, would you mind confirming that it addresses your issue? Mike On 01/23/2012 09:02 AM, Bruno Santos wrote: > Sorry it took me a while to get back to you. I have finally written > some code to replicate the problem. I have attached a file with it. > > Thank you very much in advance, > Bruno Santos > > 2012/1/19 Tony Yu <ts...@gm... <mailto:ts...@gm...>> > > > > On Thu, Jan 19, 2012 at 12:07 PM, Bruno Santos > <bac...@gm... <mailto:bac...@gm...>> wrote: > > Hello everyone, > > I have been using matplotlib 0.99.3 to write some down. But I > had to upgrade my OS and so installed the last version of the > library 1.1.0. But unfortunately when I try to run my code I > get the following error: > raise ValueError, 'Path lacks initial MOVETO' > ValueError: Path lacks initial MOVETO > > I have been goggling it and saw some reports about it when > using a vector containing zeros for which I apply a log and > then trying to plot this. But the reports seem to indicate > this was fixed in a svn version I can't access anymore. > Can anyone point me on the correct direction to solve this > problem? > > Thank you very much in advance, > Bruno Santos > > Could you provide a bit more information: Are you calling `Path` > directly? If not, do you know what in your code is calling it? A > minimal, runnable example would be very helpful. > > Cheers, > -Tony > > > > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-dev2 > > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
|
From: Bruno S. <bac...@gm...> - 2012-01-23 14:02:36
|
Sorry it took me a while to get back to you. I have finally written some code to replicate the problem. I have attached a file with it. Thank you very much in advance, Bruno Santos 2012/1/19 Tony Yu <ts...@gm...> > > > On Thu, Jan 19, 2012 at 12:07 PM, Bruno Santos <bac...@gm...>wrote: > >> Hello everyone, >> >> I have been using matplotlib 0.99.3 to write some down. But I had to >> upgrade my OS and so installed the last version of the library 1.1.0. But >> unfortunately when I try to run my code I get the following error: >> raise ValueError, 'Path lacks initial MOVETO' >> ValueError: Path lacks initial MOVETO >> >> I have been goggling it and saw some reports about it when using a vector >> containing zeros for which I apply a log and then trying to plot this. But >> the reports seem to indicate this was fixed in a svn version I can't access >> anymore. >> Can anyone point me on the correct direction to solve this problem? >> >> Thank you very much in advance, >> Bruno Santos >> >> Could you provide a bit more information: Are you calling `Path` > directly? If not, do you know what in your code is calling it? A minimal, > runnable example would be very helpful. > > Cheers, > -Tony > > |