def draw(self): # Set the tick color tick_color = 'black' # Create a gridspec to handle spacing better self.gs = gridspec.GridSpecFromSubplotSpec( 100, 100, subplot_spec=self.parent.gs0[self.pos]) self.axes = self.figure.add_subplot( self.gs[self.parent.axes_extent[0]:self.parent.axes_extent[1], self.parent.axes_extent[2]:self.parent.axes_extent[3]]) self.ex_plot = self.axes.plot( 0, 0, ls= '-', # marker = '^', markeredgecolor = self.parent.electron_color, color=self.parent.electron_color, visible=self.GetPlotParam('show_electrons') * self.GetPlotParam('show_x')) self.ey_plot = self.axes.plot( 0, 0, ls='-', #marker = 'v', markeredgecolor= self.parent.electron_color, color=self.parent.electron_color, visible=self.GetPlotParam('show_electrons') * self.GetPlotParam('show_y')) self.ey_plot[0].set_dashes([1, 1]) self.ez_plot = self.axes.plot( 0, 0, ls='-', #marker = 'd', markeredgecolor = self.parent.electron_color, color=self.parent.electron_color, visible=self.GetPlotParam('show_electrons') * self.GetPlotParam('show_z')) self.ez_plot[0].set_dashes([5, 1]) self.ix_plot = self.axes.plot( 0, 0, ls='-', #marker = '<', markeredgecolor = self.parent.ion_color, color=self.parent.ion_color, visible=self.GetPlotParam('show_ions') * self.GetPlotParam('show_x')) self.iy_plot = self.axes.plot( 0, 0, ls= '-', # marker = '*', markersize = 10, markeredgecolor = self.parent.ion_color, color=self.parent.ion_color, visible=self.GetPlotParam('show_ions') * self.GetPlotParam('show_y')) self.iy_plot[0].set_dashes([1, 1]) self.iz_plot = self.axes.plot( 0, 0, ls='-', #marker = 's', markeredgecolor = self.parent.ion_color, color=self.parent.ion_color, visible=self.GetPlotParam('show_ions') * self.GetPlotParam('show_z')) self.iz_plot[0].set_dashes([5, 1]) self.tx_plot = self.axes.plot( 0, 0, ls='-', #marker = '<', markeredgecolor = self.parent.ion_color, color=self.totalcolor, visible=self.GetPlotParam('show_total') * self.GetPlotParam('show_x')) self.ty_plot = self.axes.plot( 0, 0, ls= '-', # marker = '*', markersize = 10, markeredgecolor = self.parent.ion_color, color=self.totalcolor, visible=self.GetPlotParam('show_total') * self.GetPlotParam('show_y')) self.ty_plot[0].set_dashes([1, 1]) self.tz_plot = self.axes.plot( 0, 0, ls='-', #marker = 's', markeredgecolor = self.parent.ion_color, color=self.totalcolor, visible=self.GetPlotParam('show_total') * self.GetPlotParam('show_z')) self.tz_plot[0].set_dashes([5, 1]) if self.GetPlotParam('show_electrons'): if self.GetPlotParam('show_x'): self.ex_plot[0].set_data(*stepify(self.x_bins, self.ex)) if self.GetPlotParam('show_y'): self.ey_plot[0].set_data(*stepify(self.x_bins, self.ey)) if self.GetPlotParam('show_z'): self.ez_plot[0].set_data(*stepify(self.x_bins, self.ez)) if self.GetPlotParam('show_ions'): if self.GetPlotParam('show_x'): self.ix_plot[0].set_data(*stepify(self.x_bins, self.ix)) if self.GetPlotParam('show_y'): self.iy_plot[0].set_data(*stepify(self.x_bins, self.iy)) if self.GetPlotParam('show_z'): self.iz_plot[0].set_data(*stepify(self.x_bins, self.iz)) if self.GetPlotParam('show_total'): if self.GetPlotParam('show_x'): self.tx_plot[0].set_data(*stepify( self.x_bins, Total(self.ix, self.icounts, self.ex, self.ecounts))) if self.GetPlotParam('show_y'): self.ty_plot[0].set_data(*stepify( self.x_bins, Total(self.iy, self.icounts, self.ey, self.ecounts))) if self.GetPlotParam( 'show_z') and self.GetPlotParam('m_type') != 2: self.tz_plot[0].set_data(*stepify( self.x_bins, Total(self.iz, self.icounts, self.ez, self.ecounts))) if int(matplotlib.__version__[0]) < 2: self.axes.set_axis_bgcolor(self.GetPlotParam('face_color')) else: self.axes.set_facecolor(self.GetPlotParam('face_color')) self.axes.tick_params( labelsize=self.parent.MainParamDict['NumFontSize'], color=tick_color) # fancy code to make sure that matplotlib sets its limits # only based on visible lines self.key_list = ['show_x', 'show_y', 'show_z'] self.ion_plot_list = [ self.ix_plot[0], self.iy_plot[0], self.iz_plot[0] ] self.e_plot_list = [self.ex_plot[0], self.ey_plot[0], self.ez_plot[0]] self.t_plot_list = [self.tx_plot[0], self.ty_plot[0], self.tz_plot[0]] legend_handles = [] legend_labels = [] self.axes.dataLim = mtransforms.Bbox.unit() #self.axes.dataLim.update_from_data_xy(xy = np.vstack(self.ion_plot_list[0].get_data()).T, ignore=True) #self.axes.dataLim.update_from_data_xy(xy = np.vstack(self.e_plot_list[0].get_data()).T, ignore=True) if self.GetPlotParam('show_ions'): for i in range(len(self.ion_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.ion_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) legend_handles.append(self.ion_plot_list[i]) legend_labels.append( self.legend_labels[self.GetPlotParam('m_type')][0][i]) if self.GetPlotParam('show_electrons'): for i in range(len(self.e_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.e_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) legend_handles.append(self.e_plot_list[i]) legend_labels.append( self.legend_labels[self.GetPlotParam('m_type')][1][i]) if self.GetPlotParam('show_total'): for i in range(len(self.t_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.t_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) legend_handles.append(self.t_plot_list[i]) legend_labels.append( self.legend_labels[self.GetPlotParam('m_type')][2][i]) if self.GetPlotParam('logy'): self.axes.set_yscale('log') self.axes.autoscale() # now make the legend self.legend = self.axes.legend( legend_handles, legend_labels, framealpha=.05, fontsize=self.parent.MainParamDict['legendLabelSize'], loc=1, ncol=max( 1, self.GetPlotParam('show_ions') + self.GetPlotParam('show_electrons') + self.GetPlotParam('show_total'))) self.legend.get_frame().set_facecolor('k') self.legend.get_frame().set_linewidth(0.0) if not self.GetPlotParam('show_legend'): self.legend.set_visible(False) self.legend.set_draggable(True, update='loc') if self.GetPlotParam('legend_loc') != 'N/A': tmp_tup = float(self.GetPlotParam('legend_loc').split()[0]), float( self.GetPlotParam('legend_loc').split()[1]) self.legend._set_loc(tmp_tup) if self.GetPlotParam('set_v_min'): self.axes.set_ylim(bottom=self.GetPlotParam('v_min')) if self.GetPlotParam('set_v_max'): self.axes.set_ylim(top=self.GetPlotParam('v_max')) if self.parent.MainParamDict['SetxLim']: if self.parent.MainParamDict['xLimsRelative']: self.axes.set_xlim( self.parent.MainParamDict['xLeft'] + self.parent.shock_loc, self.parent.MainParamDict['xRight'] + self.parent.shock_loc) else: self.axes.set_xlim(self.parent.MainParamDict['xLeft'], self.parent.MainParamDict['xRight']) else: self.axes.set_xlim(self.fxmin, self.fxmax) self.axes.set_xlabel(r'$x\ [c/\omega_{pe}]$', labelpad=self.parent.MainParamDict['xLabelPad'], color='black', size=self.parent.MainParamDict['AxLabelSize']) self.axes.set_ylabel(self.ylabel_list[self.GetPlotParam('m_type')], labelpad=self.parent.MainParamDict['yLabelPad'], color='black', size=self.parent.MainParamDict['AxLabelSize'])
def refresh(self): '''This is a function that will be called only if self.axes already holds a total energy type plot. We only update things that have changed & are shown. If hasn't changed or isn't shown, don't touch it. The difference between this and last time, is that we won't actually do any drawing in the plot. The plot will be redrawn after all subplots are refreshed. ''' if self.GetPlotParam('show_electrons'): if self.GetPlotParam('show_x'): self.ex_plot[0].set_data(*stepify(self.x_bins, self.ex)) if self.GetPlotParam('show_y'): self.ey_plot[0].set_data(*stepify(self.x_bins, self.ey)) if self.GetPlotParam('show_z'): self.ez_plot[0].set_data(*stepify(self.x_bins, self.ez)) if self.GetPlotParam('show_ions'): if self.GetPlotParam('show_x'): self.ix_plot[0].set_data(*stepify(self.x_bins, self.ix)) if self.GetPlotParam('show_y'): self.iy_plot[0].set_data(*stepify(self.x_bins, self.iy)) if self.GetPlotParam('show_z'): self.iz_plot[0].set_data(*stepify(self.x_bins, self.iz)) if self.GetPlotParam('show_total'): if self.GetPlotParam('show_x'): self.tx_plot[0].set_data(*stepify( self.x_bins, Total(self.ix, self.icounts, self.ex, self.ecounts))) if self.GetPlotParam('show_y'): self.ty_plot[0].set_data(*stepify( self.x_bins, Total(self.iy, self.icounts, self.ey, self.ecounts))) if self.GetPlotParam('show_z'): self.tz_plot[0].set_data(*stepify( self.x_bins, Total(self.iz, self.icounts, self.ez, self.ecounts))) # fancy code to make sure that matplotlib sets its limits # based only on the visible lines. self.axes.dataLim = mtransforms.Bbox.unit() #self.axes.dataLim.update_from_data_xy(xy = np.vstack(self.ion_plot_list[0].get_data()).T, ignore=True) if self.GetPlotParam('show_ions'): for i in range(len(self.ion_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.ion_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) if self.GetPlotParam('show_electrons'): for i in range(len(self.e_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.e_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) if self.GetPlotParam('show_total'): for i in range(len(self.t_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.t_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) self.axes.autoscale() # Set new lims if the user chooses to do so. if self.GetPlotParam('set_v_min'): self.axes.set_ylim(bottom=self.GetPlotParam('v_min')) if self.GetPlotParam('set_v_max'): self.axes.set_ylim(top=self.GetPlotParam('v_max')) if self.parent.MainParamDict['SetxLim']: if self.parent.MainParamDict['xLimsRelative']: self.axes.set_xlim( self.parent.MainParamDict['xLeft'] + self.parent.shock_loc, self.parent.MainParamDict['xRight'] + self.parent.shock_loc) else: self.axes.set_xlim(self.parent.MainParamDict['xLeft'], self.parent.MainParamDict['xRight']) else: self.axes.set_xlim(self.fxmin, self.fxmax)
def draw(self): ''' A function that draws the data. In the interest in speeding up the code, draw should only be called when you want to recreate the whole figure, i.e. it will be slow. Most times you will only want to update what has changed in the figure. This will be done in a function called refresh, that should be much much faster.''' # Set the tick color tick_color = 'black' # Create a gridspec to handle spacing better self.gs = gridspec.GridSpecFromSubplotSpec( 100, 100, subplot_spec=self.parent.gs0[self.FigWrap.pos]) if self.parent.MainParamDict[ 'LinkSpatial'] != 0 and self.parent.MainParamDict[ 'LinkSpatial'] != 3: if self.FigWrap.pos == self.parent.first_x: self.axes = self.figure.add_subplot(self.gs[ self.parent.axes_extent[0]:self.parent.axes_extent[1], self.parent.axes_extent[2]:self.parent.axes_extent[3]]) else: self.axes = self.figure.add_subplot( self.gs[ self.parent.axes_extent[0]:self.parent.axes_extent[1], self.parent.axes_extent[2]:self.parent.axes_extent[3]], sharex=self.parent.SubPlotList[self.parent.first_x[0]][ self.parent.first_x[1]].graph.axes) else: self.axes = self.figure.add_subplot( self.gs[self.parent.axes_extent[0]:self.parent.axes_extent[1], self.parent.axes_extent[2]:self.parent.axes_extent[3]]) self.ex_plot = self.axes.plot( 0, 0, ls= '-', # marker = '^', markeredgecolor = self.parent.electron_color, color=self.parent.electron_color, visible=self.GetPlotParam('show_electrons') * self.GetPlotParam('show_x')) self.ey_plot = self.axes.plot( 0, 0, ls='-', #marker = 'v', markeredgecolor= self.parent.electron_color, color=self.parent.electron_color, visible=self.GetPlotParam('show_electrons') * self.GetPlotParam('show_y')) self.ey_plot[0].set_dashes([1, 1]) self.ez_plot = self.axes.plot( 0, 0, ls='-', #marker = 'd', markeredgecolor = self.parent.electron_color, color=self.parent.electron_color, visible=self.GetPlotParam('show_electrons') * self.GetPlotParam('show_z')) self.ez_plot[0].set_dashes([5, 1]) self.ix_plot = self.axes.plot( 0, 0, ls='-', #marker = '<', markeredgecolor = self.parent.ion_color, color=self.parent.ion_color, visible=self.GetPlotParam('show_ions') * self.GetPlotParam('show_x')) self.iy_plot = self.axes.plot( 0, 0, ls= '-', # marker = '*', markersize = 10, markeredgecolor = self.parent.ion_color, color=self.parent.ion_color, visible=self.GetPlotParam('show_ions') * self.GetPlotParam('show_y')) self.iy_plot[0].set_dashes([1, 1]) self.iz_plot = self.axes.plot( 0, 0, ls='-', #marker = 's', markeredgecolor = self.parent.ion_color, color=self.parent.ion_color, visible=self.GetPlotParam('show_ions') * self.GetPlotParam('show_z')) self.iz_plot[0].set_dashes([5, 1]) self.tx_plot = self.axes.plot( 0, 0, ls='-', #marker = '<', markeredgecolor = self.parent.ion_color, color=self.totalcolor, visible=self.GetPlotParam('show_total') * self.GetPlotParam('show_x')) self.ty_plot = self.axes.plot( 0, 0, ls= '-', # marker = '*', markersize = 10, markeredgecolor = self.parent.ion_color, color=self.totalcolor, visible=self.GetPlotParam('show_total') * self.GetPlotParam('show_y')) self.ty_plot[0].set_dashes([1, 1]) self.tz_plot = self.axes.plot( 0, 0, ls='-', #marker = 's', markeredgecolor = self.parent.ion_color, color=self.totalcolor, visible=self.GetPlotParam('show_total') * self.GetPlotParam('show_z')) self.tz_plot[0].set_dashes([5, 1]) if self.GetPlotParam('show_electrons'): if self.GetPlotParam('show_x'): self.ex_plot[0].set_data(*stepify(self.x_bins, self.ex)) if self.GetPlotParam('show_y'): self.ey_plot[0].set_data(*stepify(self.x_bins, self.ey)) if self.GetPlotParam('show_z'): self.ez_plot[0].set_data(*stepify(self.x_bins, self.ez)) if self.GetPlotParam('show_ions'): if self.GetPlotParam('show_x'): self.ix_plot[0].set_data(*stepify(self.x_bins, self.ix)) if self.GetPlotParam('show_y'): self.iy_plot[0].set_data(*stepify(self.x_bins, self.iy)) if self.GetPlotParam('show_z'): self.iz_plot[0].set_data(*stepify(self.x_bins, self.iz)) if self.GetPlotParam('show_total'): if self.GetPlotParam('show_x'): self.tx_plot[0].set_data(*stepify( self.x_bins, Total(self.ix, self.icounts, self.ex, self.ecounts))) if self.GetPlotParam('show_y'): self.ty_plot[0].set_data(*stepify( self.x_bins, Total(self.iy, self.icounts, self.ey, self.ecounts))) if self.GetPlotParam( 'show_z') and self.GetPlotParam('m_type') != 2: self.tz_plot[0].set_data(*stepify( self.x_bins, Total(self.iz, self.icounts, self.ez, self.ecounts))) if int(matplotlib.__version__[0]) < 2: self.axes.set_axis_bgcolor('lightgrey') else: self.axes.set_facecolor('lightgrey') self.axes.tick_params( labelsize=self.parent.MainParamDict['NumFontSize'], color=tick_color) # fancy code to make sure that matplotlib sets its limits # only based on visible lines self.key_list = ['show_x', 'show_y', 'show_z'] self.ion_plot_list = [ self.ix_plot[0], self.iy_plot[0], self.iz_plot[0] ] self.e_plot_list = [self.ex_plot[0], self.ey_plot[0], self.ez_plot[0]] self.t_plot_list = [self.tx_plot[0], self.ty_plot[0], self.tz_plot[0]] legend_handles = [] legend_labels = [] self.axes.dataLim = mtransforms.Bbox.unit() #self.axes.dataLim.update_from_data_xy(xy = np.vstack(self.ion_plot_list[0].get_data()).T, ignore=True) #self.axes.dataLim.update_from_data_xy(xy = np.vstack(self.e_plot_list[0].get_data()).T, ignore=True) if self.GetPlotParam('show_ions'): for i in range(len(self.ion_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.ion_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) legend_handles.append(self.ion_plot_list[i]) legend_labels.append( self.legend_labels[self.GetPlotParam('m_type')][0][i]) if self.GetPlotParam('show_electrons'): for i in range(len(self.e_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.e_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) legend_handles.append(self.e_plot_list[i]) legend_labels.append( self.legend_labels[self.GetPlotParam('m_type')][1][i]) if self.GetPlotParam('show_total'): for i in range(len(self.t_plot_list)): if self.GetPlotParam(self.key_list[i]): xy = np.vstack(self.t_plot_list[i].get_data()).T self.axes.dataLim.update_from_data_xy(xy, ignore=False) legend_handles.append(self.t_plot_list[i]) legend_labels.append( self.legend_labels[self.GetPlotParam('m_type')][2][i]) if self.GetPlotParam('logy'): self.axes.set_yscale('log') self.axes.autoscale() # now make the legend self.legend = self.axes.legend( legend_handles, legend_labels, framealpha=.05, fontsize=self.parent.MainParamDict['legendLabelSize'], loc=1, ncol=max( 1, self.GetPlotParam('show_ions') + self.GetPlotParam('show_electrons') + self.GetPlotParam('show_total'))) self.legend.get_frame().set_facecolor('k') self.legend.get_frame().set_linewidth(0.0) if not self.GetPlotParam('show_legend'): self.legend.set_visible(False) self.legend.draggable(update='loc') if self.GetPlotParam('legend_loc') != 'N/A': tmp_tup = float(self.GetPlotParam('legend_loc').split()[0]), float( self.GetPlotParam('legend_loc').split()[1]) self.legend._set_loc(tmp_tup) if self.GetPlotParam('set_v_min'): self.axes.set_ylim(ymin=self.GetPlotParam('v_min')) if self.GetPlotParam('set_v_max'): self.axes.set_ylim(ymax=self.GetPlotParam('v_max')) if self.parent.MainParamDict['SetxLim']: if self.parent.MainParamDict['xLimsRelative']: self.axes.set_xlim( self.parent.MainParamDict['xLeft'] + self.parent.shock_loc, self.parent.MainParamDict['xRight'] + self.parent.shock_loc) else: self.axes.set_xlim(self.parent.MainParamDict['xLeft'], self.parent.MainParamDict['xRight']) else: self.axes.set_xlim(self.fxmin, self.fxmax) self.axes.set_xlabel(r'$x\ [c/\omega_{pe}]$', labelpad=self.parent.MainParamDict['xLabelPad'], color='black', size=self.parent.MainParamDict['AxLabelSize']) self.axes.set_ylabel(self.ylabel_list[self.GetPlotParam('m_type')], labelpad=self.parent.MainParamDict['yLabelPad'], color='black', size=self.parent.MainParamDict['AxLabelSize'])