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 |