def plot(filename,figsize=None,xlim=None,ylim=None,\ overwrite=False,complex_op=None,**kwargs): """ Graph of 1D data file using Matplotlib plt.plot INPUTS: filename: string name of file containing 1D data to be plotted figsize: tuple (width,height) size of figure to be displayed xlim: np.array x-axis limits of graph ylim: np.array y-axis limits of graph overwrite: bool add lines to an existing plt.plot graph if it exists (default is False which will plot graph on a new figure) complex_op : string in the following list ('real','imag','power','absolute','angle') complex operation used to plot complex data **kwargs: dictionary (optional) arguments to be passed onto plt.loglog plot OUTPUTS: ax : matplotlib.axes.Axes Matplotlib axes object, allows for setting limits and other manipulation of the axes (e.g. ax.set_xlim([0,1]) would set the graph x-limits to be between 0 and 1) """ x, y, auxDict = LoadData1D(filename) if complex_op is not None: y = ProcessComplex(complex_op, y) ExtendDictionary(auxDict, figsize=figsize, xlim=xlim, ylim=ylim, overwrite=overwrite) x, y, auxDict = ProcessData1D(x, y, auxDict) figsize = PlotSize(figsize) if xlim is None: xlim = [x[0], x[-1]] if ylim is None: ylim = [np.min(y), np.max(y)] labs = plt.get_figlabels() if overwrite: if "Plot" not in labs: configs.defaultLS() else: configs.toggleLS() plt.figure("Plot", figsize=figsize) if (configs.LS == 'k--'): plt.plot(x, y, configs.LS, dashes=(4, 2), **kwargs) else: plt.plot(x, y, configs.LS, **kwargs) else: plt.figure(figsize=figsize) configs.defaultLS() plt.plot(x, y, configs.LS, **kwargs) AuxPlotLabel1D(auxDict) if 'legend' in auxDict and configs._G['legend'] == 'on': plt.legend([str(auxDict["legend"])], loc='best') if xlim: plt.xlim(xlim) if ylim: plt.ylim(ylim) plt.ion() plt.show() ax = plt.gca() return ax
def contourflog(filename, numlevels, decades, figsize=None, xlim=None, ylim=None, complex_op=None, overwrite=False, **kwargs): """ Logged data contour plot of 2D data file using Matplotlib plt.contourf INPUTS: filename: string name of file containing 2D data to be plotted numlevels : int number of contour levels to plot decades: int maximum number of log10 decades to be plotted (starting with max value) figsize: tuple (width,height) size of figure to be displayed xlim: np.array x-axis limits of graph ylim: np.array y-axis limits of graph complex_op : string (note this parameter is not used unless the data is complex) cop = 'power' -> for complex data graph the surface of the power of the data cop = 'absolute' -> for complex data graph the surface of the absolute value (abs(data)) cop = 'angle' -> for complex data graph the surface of the absolute value (angle(data)) overwrite: bool false (default) -> create new contourf plot figure true -> clear figure named 'Contourf' and make new contourf plot **kwargs: dictionary (optional) arguments to be passed onto plt.contourf plot OUTPUTS: None """ x, y, Z, auxDict = LoadData2D(filename) if complex_op is not None: Z = ProcessComplex(complex_op, Z) ExtendDictionary(auxDict,decades=decades,figsize=figsize,\ xlim=xlim,ylim=ylim,overwrite=overwrite) x, y, Z, auxDict = ProcessData2D(x, y, Z, auxDict) # Z = ProcessDecadeLimits(decades,Z) figsize = ContourfSize(figsize) X, Y = np.meshgrid(x, y) levels, levelTicks, _ = ContourLevelsL(numlevels, decades, Z) if overwrite: fig = plt.figure("Contourflog", figsize=figsize) fig.clf() else: fig = plt.figure(figsize=figsize) if 'cmap' in kwargs: cmap = kwargs['cmap'] del kwargs['cmap'] else: cmap = str(configs._G["cmap"]) plt.contourf(X, Y, Z, levels, cmap=cmap, locator=ticker.LogLocator(), **kwargs) ax = plt.gca() ax.set_xlabel(LabelX(auxDict)) ax.set_ylabel(LabelY(auxDict)) plt.colorbar(ticks=ticker.LogLocator()) plt.ion() plt.show()
def contourf(filename,levels=None,figsize=None,xlim=None,ylim=None,zlim=None,\ decades=None,complex_op=None,overwrite=False,**kwargs): """ Graph of 2D data file using Matplotlib plt.contourf INPUTS: filename: string name of file containing 2D data to be plotted levels : int or array-like (optional) determines number and position of contour lines/regions figsize: tuple (width,height) size of figure to be displayed xlim: np.array x-axis limits of graph ylim: np.array y-axis limits of graph zlim: np.array [zmin,zmax] zmin -> minimum value data can take zmax -> maximum value data can take decades: int maximum number of log10 decades to be plotted (starting with max value) overwrite: bool false (default) -> create new contourf plot figure true -> clear figure named 'Contourf' and make new contourf plot complex_op : string in the following list ('real','imag','power','absolute','angle') complex operation used to plot complex data **kwargs: dictionary (optional) arguments to be passed onto plt.contourf plot OUTPUTS: None """ x, y, Z, auxDict = LoadData2D(filename) if complex_op is not None: Z = ProcessComplex(complex_op, Z) ExtendDictionary(auxDict,levels=levels,figsize=figsize,xlim=xlim,ylim=ylim,zlim=zlim,\ decades=decades,overwrite=overwrite) x, y, Z, auxDict = ProcessData2D(x, y, Z, auxDict) figsize = ContourfSize(figsize) X, Y = np.meshgrid(x, y) if zlim is not None: Z = ProcessContourLimitZ(zlim, Z) levels, levelTicks, _ = ContourLevels(levels, Z) if overwrite: fig = plt.figure("Contourf", figsize=figsize) fig.clf() else: fig = plt.figure(figsize=figsize) if 'cmap' in kwargs: cmap = kwargs['cmap'] del kwargs['cmap'] else: cmap = str(configs._G["cmap"]) plt.contourf(X, Y, Z, levels, cmap=cmap, **kwargs) ax = plt.gca() ax.set_xlabel(LabelX(auxDict)) ax.set_ylabel(LabelY(auxDict)) plt.colorbar(ticks=levelTicks, format='%0.2e') plt.ion() plt.show()
def loglog(filename,figsize=None,decades=None,xlim=None,ylim=None,\ complex_op=None,overwrite=False,**kwargs): """ Loglog graph of 1D data file using Matplotlib plt.loglog INPUTS: filename: string name of file containing 1D data to be plotted figsize: tuple (width,height) size of figure to be displayed xlim: np.array x-axis limits of graph ylim: np.array x-axis limits of graph decades: int number of decades of data below maximum to plot overwrite: bool add lines to an existing plt.semilogy graph if it exists (default is False which will create graph on a new figure) **kwargs: dictionary (optional) arguments to be passed onto plt.loglog plot OUTPUTS: ax : matplotlib.axes.Axes Matplotlib axes object, allows for setting limits and other manipulation of the axes (e.g. ax.set_xlim([0,1]) would set the graph x-limits to be between 0 and 1) """ x, y, auxDict = LoadData1D(filename) if complex_op is not None: y = ProcessComplex(complex_op, y) if decades is None: decades = configs._G['decades'] if xlim is None: xlim = [x[0], x[-1]] if ylim is None: ylim = [np.min(y), np.max(y)] figsize = LogLogSize(figsize) ExtendDictionary(auxDict,figsize=figsize,decades=decades,\ xlim=xlim,ylim=ylim,overwrite=overwrite) x, y, auxDict = ProcessData1D(x, y, auxDict) figsize = LogLogSize(figsize) if overwrite: labs = plt.get_figlabels() if "LogLog" not in labs: configs.defaultLS() else: configs.toggleLS() plt.figure("LogLog", figsize=figsize) else: configs.defaultLS() plt.figure(figsize=figsize) fig = plt.loglog(x, y, configs.LS, **kwargs) plt.grid(True) AuxPlotLabelLL1D(auxDict) if xlim: plt.xlim(xlim) if ylim: plt.ylim(ylim) plt.ion() plt.show() return fig
def surface(filename,figsize=None,xlim=None,ylim=None,zlim=None,\ overwrite=False,complex_op=None,**kwargs): """ Graph of 2D data file using Matplotlib plt.surface INPUTS: filename: string name of file containing 2D data to be plotted figsize: tuple (width,height) size of figure to be displayed xlim: np.array x-axis limits of graph ylim: np.array y-axis limits of graph zlim: np.array z-axis limits of graph overwrite: bool false (default) -> create new surface plot figure true -> clear figure named 'Surface' and make new surface plot complex_op : string in the following list ('real','imag','power','absolute','angle') complex operation used to plot complex data **kwargs: dictionary (optional) arguments to be passed onto plt.surface plot OUTPUTS: None """ x, y, Z, auxDict = LoadData2D(filename) if complex_op is not None: Z = ProcessComplex(complex_op, Z) ExtendDictionary(auxDict, figsize=figsize, xlim=xlim, ylim=ylim, overwrite=overwrite) x, y, Z, auxDict = ProcessData2D(x, y, Z, auxDict) figsize = SurfaceSize(figsize) elev, azim = GetView(**kwargs) auxDict['elev'] = elev auxDict['azim'] = azim if xlim is None: xlim = [x[0], x[-1]] if ylim is None: ylim = [y[0], y[-1]] X, Y = np.meshgrid(x, y) if 'cmap' in kwargs: cmap = kwargs['cmap'] else: cmap = str(configs._G["cmap"]) if overwrite: fig = plt.figure("Surface", figsize=figsize) fig.clf() else: fig = plt.figure(figsize=figsize) ax = fig.add_subplot(projection='3d') ax.w_xaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) ax.w_yaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) ax.w_zaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cmap, linewidth=0, antialiased=True, shade=True, **kwargs) if zlim: ax.set_zlim3d(zlim) xlabel, ylabel, zlabel = Labels2D(auxDict) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) ax.set_zlabel(zlabel) ax.view_init(auxDict['elev'], auxDict['azim']) numTicks = int(configs._G['NumberSurfaceTicks']) ax.xaxis.set_major_locator(ticker.LinearLocator(numTicks)) ax.yaxis.set_major_locator(ticker.LinearLocator(numTicks)) ax.zaxis.set_major_locator(ticker.LinearLocator(4)) labelType = str(configs._G['SurfaceTickFormat']) ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(labelType)) ax.yaxis.set_major_formatter(ticker.FormatStrFormatter(labelType)) ax.zaxis.set_major_formatter(ticker.FormatStrFormatter(labelType)) plt.ion() plt.show()
def waterfall(fileID : str, fileNumbers : list,figsize=None,xlim=None,ylim=None,\ complex_op=None,zvalstr=None,aspect=None,**kwargs): """ INPUTS: fileID: str ID for data files where files look like fileID_fileNum.dat e.g. if data files for T data are T_0.dat,T_1.dat, T_2.dat,..., then the fileID is simply 'T' (extension is a catchall, doesnt have to be dat) fileNumbers: list[int] Specifies which data file numbers to plot e.g. waterfall('T',[0:2:100]) will plot files T_0.dat,T_2.dat,...,T_100.dat (see graphdata.plot.plot for info on other arguments) xlim: np.array x-axis limits of graph zlim: np.array z-axis limits of graph complex_op : string in the following list ('real','imag','power','absolute','angle') complex operation used to plot complex data zvalstr: str looks for metadata labeled zvalstr in the files, and will use these to plot z-axis with units aspect: tuple aspect ratio to use for xyz graph, e.g. (1,1,1) corresponds to a box **kwargs: dictionary (optional) arguments to be passed onto plt.plot plots OUTPUTS: ax : matplotlib.axes.Axes Matplotlib axes object, allows for setting limits and other manipulation of the axes (e.g. ax.set_xlim([0,1]) would set the graph x-limits to be between 0 and 1) """ fileList = GetDataFileList(fileID, fileNumbers) fileLen = len(fileList) count = 0 auxDict = dict() x1 = [0] * len(fileList) figsize = WaterfallSize(figsize) fig = plt.figure(figsize=figsize) ax = fig.add_subplot(projection='3d') ax.w_xaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) ax.w_yaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) ax.w_zaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) count = 0 normFact = 1.0 for i, filename in enumerate(fileList): x, y, auxDict = LoadData1D(filename) if complex_op is not None: y = ProcessComplex(complex_op, y) ExtendDictionary(auxDict,figsize=figsize,xlim=xlim,\ ylim=ylim,complex_op=complex_op) x, y, auxDict = ProcessData1D(x, y, auxDict) if zvalstr is not None and zvalstr in auxDict: x1[i] = float(auxDict[zvalstr]) else: x1[i] = i ax.plot(x, x1[i] * np.ones_like(x), y, color='black', **kwargs) if xlim is None: xlim = [x[0], x[-1]] plt.xlim(xlim) if ylim is not None: ax.set_zlim3d(ylim) zmin = np.amin(x1) zmax = np.amax(x1) plt.ylim([zmin, zmax]) if 'xlabel' in auxDict: ax.set_xlabel(auxDict['xlabel']) else: ax.set_xlabel('x') if 'ylabel' in auxDict: ax.set_zlabel(auxDict['ylabel']) else: ax.set_zlabel('y') if zvalstr is not None: ax.set_ylabel(zvalstr) else: ax.set_ylabel('file') elev, azim = GetView(**kwargs) ax.view_init(elev, azim) if aspect is not None: ax.set_box_aspect(aspect=aspect) plt.ion() plt.show() plt.tight_layout() return ax