Re: [Tutor] Looping over histogram plots
On 27/06/2012 08:47, Alan Gauld wrote: On 27/06/12 00:32, Elaina Ann Hyde wrote: Thanks for the comment, the set type is no problem for me, this is just a variable that I call set... and it works great for my purposes, It may work just now but if you ever decide you need to use a Python set you will be unable to because you have effectively hidden that data type. And it's unlikely to beimmediately obvious why its not working. That's why its a bad idea to use the built-in type names as variables. eg: myList = [1,2,3,3,4,5,6,3,1,5] myUniqueList = list(set(mylist)) # remove duplicates In your program the second line would fail. If you are confident you will never use sets then its not an issue, but these decisions have a habit of coming back to bite you in the future! And they always seem to bite the most tender part of the anatomy that they can find :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looping over histogram plots
On Wed, Jun 27, 2012 at 08:47:08AM +0100, Alan Gauld wrote: > On 27/06/12 00:32, Elaina Ann Hyde wrote: > > > Thanks for the comment, the set type is no problem for me, this is > >just a variable that I call set... and it works great for my purposes, > > It may work just now but if you ever decide you need to use a Python set > you will be unable to because you have effectively hidden that data > type. And it's unlikely to beimmediately obvious why its not working. > That's why its a bad idea to use the built-in type names as variables. This is called "shadowing a built-in", and is discouraged for exactly the reasons that Alan mentions. It is much less risky to shadow built-ins inside small functions, so you are not surprised that the built-in doesn't work as expected. When you do it deliberately to change the behaviour of a built-in, it is often called "monkey-patching"[1] which is a risky, sometimes useful but advanced technique. Nevertheless, any of these cases should be used with care, and only if necessary. [1] Sometimes called "raving insanity" *grin* -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looping over histogram plots
On 27/06/12 00:32, Elaina Ann Hyde wrote: Thanks for the comment, the set type is no problem for me, this is just a variable that I call set... and it works great for my purposes, It may work just now but if you ever decide you need to use a Python set you will be unable to because you have effectively hidden that data type. And it's unlikely to beimmediately obvious why its not working. That's why its a bad idea to use the built-in type names as variables. eg: myList = [1,2,3,3,4,5,6,3,1,5] myUniqueList = list(set(mylist)) # remove duplicates In your program the second line would fail. If you are confident you will never use sets then its not an issue, but these decisions have a habit of coming back to bite you in the future! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looping over histogram plots
Yay Python: The solution was a syntax one, if anyone else ever feels like massively multi-plotting histograms, here is the working code: #-- fig, axes = plt.subplots(nrows=5, ncols=6, figsize=(12,6)) index=0 for b in axes: for ax in b: index=index+1 set=(dat['a'+str(index)] == 1.00) #write the data n, bins, patches = ax.hist(VGSR[set], 30, normed=1) #label the axis if index==13.0: ax.set_ylabel('counts') if index >= 25.0: ax.set_xlabel('VGSR') plt.show() #--- ~Elaina Hyde -- PhD Candidate Department of Physics and Astronomy Faculty of Science Macquarie University North Ryde, NSW 2109, Australia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looping over histogram plots
Dear Don, Thanks for the comment, the set type is no problem for me, this is just a variable that I call set... and it works great for my purposes, I do suspect it is something in the way that matplotlib/pyplot deals with histograms, but I have not so far been able to find the right syntax. Note, the first code example works great, it is only the second (with the hist attempt) that does not do well. It creates 29 blank plots and 1 histogram instead of 30 histograms... so probably it does need a different phrasing, but the one you suggest gives invalid syntax. ~Elaina On Tue, Jun 26, 2012 at 9:19 PM, Don Jennings wrote: > > Message: 1 > > Date: Tue, 26 Jun 2012 18:40:50 +1000 > > From: Elaina Ann Hyde > > To: tutor@python.org > > Subject: [Tutor] Looping over histogram plots > > > > >set=(dat['a'+str(index)] == 1.00) > > You should not override the builtin set() type [1] as you've done here by > assigning it. > > > #write the data > >P.hist(VGSR[set],bins=30, normed=True) > > I am not familiar with matplotlib, etc. but given that the primary > difference in your two code samples is where you write the data, I suspect > you want something like: > >ax.plot(P.hist(VGSR[set],bins=30, normed=True)) > > Take care, > Don > > [1] http://docs.python.org/library/stdtypes.html#set -- PhD Candidate Department of Physics and Astronomy Faculty of Science Macquarie University North Ryde, NSW 2109, Australia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looping over histogram plots
> Message: 1 > Date: Tue, 26 Jun 2012 18:40:50 +1000 > From: Elaina Ann Hyde > To: tutor@python.org > Subject: [Tutor] Looping over histogram plots >set=(dat['a'+str(index)] == 1.00) You should not override the builtin set() type [1] as you've done here by assigning it. > #write the data >P.hist(VGSR[set],bins=30, normed=True) I am not familiar with matplotlib, etc. but given that the primary difference in your two code samples is where you write the data, I suspect you want something like: ax.plot(P.hist(VGSR[set],bins=30, normed=True)) Take care, Don [1] http://docs.python.org/library/stdtypes.html#set ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor