From: Delbert D. F. <dd...@lk...> - 2005-02-01 06:16:09
|
I have made great progress with my GUI to plot time-series files from my unsteady-flow modeling software. It works when I have one subplot per figure but I have not been able to get two subplots (211 and 212) to work. Only the lower subplot appears and the trace or line assigned to the upper subplot (211) appears in the lower subplot. The space for the upper subplot appears as blank space in the figure. I'm a little unsure of how to embed multiple subplots using Tk. I based what I did on examples using pylab and tried to translate them to my case. Here's the code that does the work. The fg.fgs..., is a data structure that holds various descriptive items for the figure, subplot, and the various traces. The case that fails has 2 subplots with one trace per subplot. file_list holds various file-related objects that get the data from one or more files when it is needed. ifg = 0 win = Toplevel(bd=5, relief=RIDGE) win.title(fg.fgs[ifg].name) # Try to setup useful time-series axis days = DayLocator(range(1,32)) hours = HourLocator((6,12,18)) timeformat = DateFormatter('%d %b %y') w = int(fg.fgs[ifg].width) h = int(fg.fgs[ifg].height) f = Figure(figsize=(w, h), dpi=120) nsp = len(fg.fgs[ifg].sp) # ax = [] for isp in xrange(nsp): ax = f.add_subplot(fg.fgs[ifg].sp[isp].loc_code) ntr = len(fg.fgs[ifg].sp[isp].tr) for itr in xrange(ntr): i = fg.fgs[ifg].sp[isp].tr[itr].file_index jt_0, f_0 = file_list[i].get_ts_segment() jt_0 += 678576.0 ax.plot_date(jt_0, f_0, fg.fgs[ifg].sp[isp].tr[itr].plot_code) ax.xaxis.set_major_locator(days) ax.xaxis.set_minor_locator(hours) ax.autoscale_view() labels = ax.get_xticklabels() ax.xaxis.set_major_formatter(timeformat) set(labels, rotation=85) ax.set_xlabel(fg.fgs[ifg].sp[isp].xlabel) ax.set_ylabel(fg.fgs[ifg].sp[isp].ylabel) ax.grid(True) ax.set_title(fg.fgs[ifg].title) canvas = FigureCanvasTkAgg(f, master=win) canvas.show() canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) toolbar = NavigationToolbar( canvas, win ) toolbar.update() canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1) canvas._tkcanvas.pack(side=TOP, expand=1) canvas.print_figure('test.ps', dpi=300, orientation='landscape') I'm finding that Python and matplotlib are fun to use but I'm still low on the learning curve. However, I already have a usable package and can now start adding refinements and extensions. Thanks, Delbert Franz |
From: John H. <jdh...@ac...> - 2005-02-01 13:48:41
|
>>>>> "Delbert" == Delbert D Franz <dd...@lk...> writes: Delbert> I have made great progress with my GUI to plot Delbert> time-series files from my unsteady-flow modeling Delbert> software. It works when I have one subplot per figure Delbert> but I have not been able to get two subplots (211 and Delbert> 212) to work. Only the lower subplot appears and the Delbert> trace or line assigned to the upper subplot (211) appears Delbert> in the lower subplot. The space for the upper subplot Delbert> appears as blank space in the figure. You code looks correct on first glance (except did you mean tht title to be in the loop?) . My guess is your data structure has a bug in it. Add a print statement and make sure the loc code is as you think it is. print fg.fgs[ifg].sp[isp].loc_code ax = f.add_subplot(fg.fgs[ifg].sp[isp].loc_code) If they are correct, you need to compose a minimum, free standing script that replicates your problem and I can take a look. Hope this helps, JDH |
From: Delbert D. F. <dd...@lk...> - 2005-02-02 04:51:45
|
John, Thanks for the tip. I had thought of checking that as well as I drifted off to sleep. That was it-in spades. I had input two different subplot codes but somehow only one got saved. Then I got suckered in by the simplicity of initializing the list using [ 2*Subpdata() ] where Subpdata is a class defining the various attributes of a subplot in my program. However, I soon found out that this made my problem worse; Python went into an endless loop. Again, this gave me two subplot codes but they were the same. The simple list initialization binds the same instance object to the two list entries. Not what I wanted. After using a for statement to initialize, I got my two subplots. I am now able to create multiple figures, each with one or more subplots with my software. What a great collection of software. Thanks for all the work. I tried using mx.datetime to create an mx.datetime instance which worked fine. However, mx2num() fails with python claiming an undefined mxdates. I checked the source and found only one mxdates. No idea how it should be defined. In the mean time I am using a datetime instance but I lose a small bit of precision with only integer seconds. Delbert On Tuesday 01 February 2005 05:38 am, John Hunter wrote: > >>>>> "Delbert" == Delbert D Franz <dd...@lk...> writes: > > Delbert> I have made great progress with my GUI to plot > Delbert> time-series files from my unsteady-flow modeling > Delbert> software. It works when I have one subplot per figure > Delbert> but I have not been able to get two subplots (211 and > Delbert> 212) to work. Only the lower subplot appears and the > Delbert> trace or line assigned to the upper subplot (211) appears > Delbert> in the lower subplot. The space for the upper subplot > Delbert> appears as blank space in the figure. > > You code looks correct on first glance (except did you mean tht title > to be in the loop?) . My guess is your data structure has a bug in > it. Add a print statement and make sure the loc code is as you think > it is. > > print fg.fgs[ifg].sp[isp].loc_code > ax = f.add_subplot(fg.fgs[ifg].sp[isp].loc_code) > > If they are correct, you need to compose a minimum, free standing > script that replicates your problem and I can take a look. > > Hope this helps, > JDH > > |
From: John H. <jdh...@ac...> - 2005-02-02 15:46:05
|
>>>>> "Delbert" == Delbert D Franz <dd...@lk...> writes: Delbert> I am now able to create multiple figures, each with one Delbert> or more subplots with my software. What a great Delbert> collection of software. Thanks for all the work. Great, glad it helped. I was pretty sure that was the answer. Delbert> I tried using mx.datetime to create an mx.datetime Delbert> instance which worked fine. However, mx2num() fails with Delbert> python claiming an undefined mxdates. I checked the Delbert> source and found only one mxdates. No idea how it should Delbert> be defined. In the mean time I am using a datetime Delbert> instance but I lose a small bit of precision with only Delbert> integer seconds. Oops, replace mx2num in matplotlib/dates.py with def mx2num(mxdates): """ Convert mx datetime instance (or sequence of mx instances) to the new date format, """ scalar = False if not iterable(mxdates): scalar = True mxdates = [mxdates] ret = epoch2num([m.ticks() for m in mxdates]) if scalar: return ret[0] else: return ret Thanks for the report! JDH |