def SavePlot(y, filename, xtitle='', ytitle='', title=''): plot = Figure(figsize=(12, 3)) ax = plot.add_subplot(111) # plot.grid(True) ax.set_title(title) ax.set_xlabel(xtitle) ax.set_ylabel(ytitle) # ax.axis(ymax=1, ymin =-3) plot.subplots_adjust(left=0.1, bottom=0.2) x = range(len(y)) # ax.plot(x, nu.log2(Y)) ax.plot(x, y) FigureCanvasAgg(ax.get_figure()).print_figure(filename, dpi=120) return
def timeseries_station_page(ms, station_name, time_slots, data, fn=abs, output_name=None): dpi=50 if output_name is None: fig = figure(figsize=(32,24), dpi=dpi) else: fig = Figure(figsize=(32,24), dpi=dpi) station_name_list = list(ms.tables['antennae']['NAME']) station_id = station_name_list.index(station_name) num_ant = len(ms.tables['antennae']) tsn = time_slots-time_slots[0] pol_names = corr_type(ms.tables['polarization']['CORR_TYPE'][0]) ref_freq_mhz = ms.tables['spectral_windows'][0]['REF_FREQUENCY']/1.e6 fig.suptitle(ms.msname+': '+fn.__name__+'(vis) with '+station_name+' at %3.2f MHz' % (ref_freq_mhz,), fontsize='large') median_amp = ma.median(ma.mean(ma.median(fn(data[station_id,:,0::3,:]), axis=-1), axis=-1), axis=-1) for id2,name in enumerate(station_name_list): ax = fig.add_subplot(ceil(num_ant/4.0),4, id2+1) ax.plot(tsn, fn(data[station_id,id2,0,:]), c='blue' , label=pol_names[0]) ax.plot(tsn, fn(data[station_id,id2,1,:]), c='green' , label=pol_names[1]) ax.plot(tsn, fn(data[station_id,id2,2,:]), c='purple', label=pol_names[2]) ax.plot(tsn, fn(data[station_id,id2,3,:]), c='red' , label=pol_names[3]) ax.grid() ax.set_ylabel(station_name_list[id2], rotation='horizontal') ax.set_ylim(0.0, 3*median_amp) ax.set_yticklabels([]) if id2 < len(station_name_list)-4: ax.set_xticklabels([]) else: ax.set_xlabel('Time [s]') pass fig.subplots_adjust(hspace=0.0, top=0.95, bottom=0.04) if output_name is not None: canvas = FigureCanvasAgg(fig) if output_name[-4:] in ['.jpg', '.JPG']: canvas.print_jpg(output_name, dpi=dpi, quality=55) else: canvas.print_figure(output_name, dpi=dpi) pass pass
T = np.sqrt(1.0 - R ** 2) D = T ** 4 + 4 * R ** 2 * np.sin(2 * np.pi * (w + w_hene) / c * L) ** 2 I = T ** 4 / D # Saturation radiation density Ws = hbar * (w_hene) ** 3 / np.pi ** 2 / c ** 2 # Create the figure instance if use_mpl: fig = Figure() else: fig = pl.figure(prog_title) # Create the axes for the main plot and plot the initial data axes = fig.add_subplot(111) fig.subplots_adjust(bottom=0.25) plt, = axes.plot(c / (w + w_hene) * 1e9, F * I * 1e6, "r") # Declare the areas dedicated for the slider controls axes_length = fig.add_axes([0.17, 0.12, 0.73, 0.03]) axes_reflect = fig.add_axes([0.17, 0.06, 0.73, 0.03]) # If using matplotlib, we must create the canvas area of the Window before # creating the actual Sliders. if use_mpl: # Create root Tk widget and set the title root = tk.Tk() root.title(prog_title) # Create and pack the renderable area of the widget, using the figure class plot_widget = FigureCanvasTkAgg(fig, master=root)