def MicrOscilloscope1(SoundBoard, Rate, YLim, FreqBand, MicSens_VPa, FramesPerBuf=512, Rec=False): Params = {'backend': 'Qt5Agg'} from matplotlib import rcParams; rcParams.update(Params) import matplotlib.animation as animation from matplotlib import pyplot as plt SBInAmpF = Hdf5F.SoundCalibration(SBAmpFsFile, SoundBoard, 'SBInAmpF') r = pyaudio.PyAudio() Plotting = r.open(format=pyaudio.paFloat32, channels=1, rate=Rate, input=True, output=False, #input_device_index=18, frames_per_buffer=FramesPerBuf) #stream_callback=InCallBack) Fig = plt.figure() Ax = plt.axes(xlim=FreqBand, ylim=YLim) Plot, = Ax.plot([float('nan')]*(Rate//10), lw=1) def AnimInit(): Data = array.array('f', []) Plot.set_ydata(Data) return Plot, def PltUp(n): # Data = array.array('f', Plotting.read(Rate//10)) Data = array.array('f', Plotting.read(Rate//10, exception_on_overflow=False)) Data = [_ * SBInAmpF for _ in Data] HWindow = signal.hanning(len(Data)//(Rate/1000)) F, PxxSp = signal.welch(Data, Rate, HWindow, nperseg=len(HWindow), noverlap=0, scaling='density') Start = np.where(F > FreqBand[0])[0][0]-1 End = np.where(F > FreqBand[1])[0][0]-1 BinSize = F[1] - F[0] RMS = sum(PxxSp[Start:End] * BinSize)**0.5 dB = 20*(math.log(RMS/MicSens_VPa, 10)) + 94 print(dB, max(PxxSp)) Plot.set_xdata(F) Plot.set_ydata(PxxSp) return Plot, Anim = animation.FuncAnimation(Fig, PltUp, frames=FramesPerBuf, interval=16, blit=False) if Rec: Writers = animation.writers['ffmpeg'] Writer = Writers(fps=15, metadata=dict(artist='Me')) Anim.save('MicrOscilloscope.mp4', writer=Writer) plt.show() return(None)
def imshow_wrapper(H, title=None, fname=None, size=(2.2, 2.2), adjust=0.): fig = plt.figure() ax = fig.add_subplot(111) font = {'family' : 'normal', 'weight' : 'bold', 'size' : 8} matplotlib.rc('font', **font) rcParams.update({'figure.autolayout': True}) plt.imshow(H, cmap=cm.Greys) plt.colorbar() plt.xlabel('column index') plt.ylabel('row index') if title == None: plt.title('Entries of H') else: plt.title(title) xticks = ax.xaxis.get_major_ticks() xticks[-1].label1.set_visible(False) yticks = ax.yaxis.get_major_ticks() yticks[-1].label1.set_visible(False) F = plt.gcf() F.subplots_adjust(left=adjust) plt.show() F.set_size_inches(size) if fname != None: fig.savefig(fname + '.eps')
def draw_bar(means, density): from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) ind = np.arange(len(means)) # the x locations for the groups width = 0.35 # the width of the bars fig, ax = plt.subplots() rects = ax.bar(ind, means, width, color='g') # add some text for labels, title and axes ticks ax.set_ylabel('Milliseconds') ax.set_title('Average running time on %s networks' % density) ax.set_xticks(ind+width) ax.set_xticklabels(('Ford-Fulkerson', 'Edmonds-Karp', 'Capacity scaling', 'Generic push relabel', 'Relabel to front'), rotation=40, ha='right', fontsize=10) def autolabel(rects): # attach some text labels for i, rect in enumerate(rects): height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2., height + 0.05, '%d' % means[i], ha='center', va='bottom') autolabel(rects) plt.savefig(util.get_out_file('chart', '%s.png' % density))
def rcParams(self): """ Return rcParams dict for this theme. Notes ----- Subclasses should not need to override this method method as long as self._rcParams is constructed properly. rcParams are used during plotting. Sometimes the same theme can be achieved by setting rcParams before plotting or a apply after plotting. The choice of how to implement it is is a matter of convenience in that case. There are certain things can only be themed after plotting. There may not be an rcParam to control the theme or the act of plotting may cause an entity to come into existence before it can be themed. """ try: rcParams = deepcopy(self._rcParams) except NotImplementedError: # deepcopy raises an error for objects that are drived from or # composed of matplotlib.transform.TransformNode. # Not desirable, but probably requires upstream fix. # In particular, XKCD uses matplotlib.patheffects.withStrok rcParams = copy(self._rcParams) for th in self.themeables.values(): rcParams.update(th.rcParams) return rcParams
def config_plot(self, arg_list): """Configure global plot parameters""" from matplotlib import rcParams # set rcParams rcParams.update( { "figure.dpi": 100.0, "font.family": "sans-serif", "font.size": 16.0, "font.weight": "book", "legend.loc": "best", "lines.linewidth": 1.5, "text.usetex": "true", "agg.path.chunksize": 10000, } ) # determine image dimensions (geometry) self.width = 1200 self.height = 768 if arg_list.geometry: try: self.width, self.height = map(float, arg_list.geometry.split("x", 1)) self.height = max(self.height, 500) except (TypeError, ValueError) as e: e.args = ("Cannot parse --geometry as WxH, e.g. 1200x600",) raise self.dpi = rcParams["figure.dpi"] self.xinch = self.width / self.dpi self.yinch = self.height / self.dpi rcParams["figure.figsize"] = (self.xinch, self.yinch) return
def __init__(self, parent): gui.MainFrame.__init__(self, parent) self.summaryFiles = [] self.activeSummaryFiles = [] self.testedAssemblers = [] self.summaryParsers = [] self.summaryLabels = [] self.covData = {} self.covDataKeys = [] self.covDataValues = [] self.plotIndex = 0 self.plotDir = '' self.newEntry = '' self.xAttribute = 'l' self.yAttribute = 'cN50' self.xUnits = 'bp' self.yUnits = 'bp' self.xScale = 'linear' self.yScale = 'linear' self.readFile = '' self.referencePickerName = '' self.contigPickerName = '' self.deBrujinAssemblers = ['abyss','ray','soap','velvet'] self.deBrujin = ('ABySS assembler', 'SOAPdenovo2', 'Velvet', 'Ray assembler') self.styles = [] rcParams.update({'figure.autolayout': True}) self.atributes = ['l', 'cov', 'N', 'd', 'e', 'r', 'R', 'X', 'A', 'D'] self.units = ['bp', 'coverage', 'num reads', '', '', '', '', '', '', ''] self.detailsDict = {'cTotalNum':'(number of contigs)', 'cBiggerThen':'(num. of contigs bigger then s)', 'cTotalLen' : '(total length of contigs)', 'cMaxLen' : '(maximum length of contigs)', 'cMinLen' : '(minimum length of contigs)', 'cAvgLen' : '(average length of contigs)', 'cMedLen' : '(median length of contigs)', 'cN50':'(N50 size of contigs)', 'cN25':'(N25 size of contigs)', 'cN75':'(N75 size of contigs)', 'cN56':'(N56 size of contigs)', 'sTotalNum':'(number of scaffolds)', 'sBiggerThen':'(num. of scaffolds bigger then s)', 'sTotalLen' : '(total length of scaffolds)','sMaxSize' : '(maximum length of scaff.)', 'sMinSize' : '(minimum length of scaff.','sAvgLen' : '(average length of scaff.)', 'sMedSize' : '(median length of scaff.)', 'sN50':'(N50 size of scaffolds)', 'sN25':'(N25 size of scaffolds)','sN56':'(N56 size of scaffolds)', 'sN75':'(N75 size of scaffolds)','sEM':'(ratio between median and E-size[scaff.])', 'sEN':'(ratio between n50 and E-size)','mAvgs':'(average length of scaff./average length of cont.)', 'mN50s':'(N50[contigs]/N50[scaffolds])','mNums':'([number of contigs]/[number of scaffolds])', 'mLens':'([total len. of cont.]/[total len. of scaff.])', 'mMaxs':'([max length of con.]/[max length of scaff.])', 'totalRealTime':'(total execution time of all steps of the assembly process)', 'totalCpuTime':'(total CPU time of all steps of the assembly process)', 'totalRSS':'(peak memory usage [Resident Set Size])', 'l':'(read length)', } self.atributes += ['totalRealTime', 'totalCpuTime', 'totalRSS', 'totalPSS', 'totalVmSize', 'cTotalNum', 'cBiggerThen', \ 'cTotalLen', 'cMaxLen', 'cMinLen', 'cAvgLen', 'cMedLen', 'cESize', 'cN25', 'cN50', 'cN56', 'cN75', 'sTotalNum', \ 'sMaxSize', 'sMinSize', 'sAvgSize', 'sMedSize', 'sCertainNum', 'sN25', 'sN50', 'sN56', 'sN75', 'sEM', 'sEN', 'sQual', 'mAvgs', 'mN50s', 'mNums', 'mLens', 'mMaxs','cReferenceCoverage'] self.units += ['sec', 'sec', 'MB', 'MB', 'MB', '', '', \ 'bp', 'bp', 'bp', 'bp', 'bp', '', 'bp', 'bp', 'bp', 'bp', '', \ 'bp', 'bp', 'bp', 'bp', '', 'bp', 'bp', 'bp', 'bp', '', '', \ '', '', '', '', '', '','']; self.selectionMap = {0:'linear',1:'logarithmic'} self.checkListBoxInitialItems = {"abyss":0,"minimus":1,"sga":2,"pasqual":3,"soap":4,"celera":5,"velvet":6,"readjoiner":7, "ray":8} self.assemblerTypes = {} print "[AN:] Basic viewer 1.0 started at: ", time.strftime("%H:%M:%S") self.CreatePlot() self.createReadsPlot()
def test_bbox_inches_tight(): #: Test that a figure saved using bbox_inches='tight' is clipped right rcParams.update(rcParamsDefault) data = [[ 66386, 174296, 75131, 577908, 32015], [ 58230, 381139, 78045, 99308, 160454], [ 89135, 80552, 152558, 497981, 603535], [ 78415, 81858, 150656, 193263, 69638], [139361, 331509, 343164, 781380, 52269]] colLabels = rowLabels = [''] * 5 rows = len(data) ind = np.arange(len(colLabels)) + 0.3 # the x locations for the groups cellText = [] width = 0.4 # the width of the bars yoff = np.array([0.0] * len(colLabels)) # the bottom values for stacked bar chart fig, ax = plt.subplots(1, 1) for row in xrange(rows): plt.bar(ind, data[row], width, bottom=yoff) yoff = yoff + data[row] cellText.append(['']) plt.xticks([]) plt.legend([''] * 5, loc=(1.2, 0.2)) # Add a table at the bottom of the axes cellText.reverse() the_table = plt.table(cellText=cellText, rowLabels=rowLabels, colLabels=colLabels, loc='bottom')
def graph(csv_file, filename, bytes2str): '''Create a line graph from a two column csv file.''' unit = configs['unit'] date, value = np.loadtxt(csv_file, delimiter=',', unpack=True, converters={0: bytes2str} ) fig = plt.figure(figsize=(10, 3.5)) fig.add_subplot(111, axisbg='white', frameon=False) rcParams.update({'font.size': 9}) plt.plot_date(x=date, y=value, ls='solid', linewidth=2, color='#FB921D', fmt=':' ) title = "Sump Pit Water Level {}".format(time.strftime('%Y-%m-%d %H:%M')) title_set = plt.title(title) title_set.set_y(1.09) plt.subplots_adjust(top=0.86) if unit == 'imperial': plt.ylabel('inches') if unit == 'metric': plt.ylabel('centimeters') plt.xlabel('Time of Day') plt.xticks(rotation=30) plt.grid(True, color='#ECE5DE', linestyle='solid') plt.tick_params(axis='x', bottom='off', top='off') plt.tick_params(axis='y', left='off', right='off') plt.savefig(filename, dpi=72)
def config_plot(self, arg_list): """Configure global plot parameters""" import matplotlib from matplotlib import rcParams # set rcParams rcParams.update({ 'figure.dpi': 100., 'font.family': 'sans-serif', 'font.size': 16., 'font.weight': 'book', 'legend.loc': 'best', 'lines.linewidth': 1.5, 'text.usetex': 'true', 'agg.path.chunksize': 10000, }) # determine image dimensions (geometry) self.width = 1200 self.height = 768 if arg_list.geometry: try: self.width, self.height = map(float, arg_list.geometry.split('x', 1)) self.height = max(self.height, 500) except (TypeError, ValueError) as e: e.args = ('Cannot parse --geometry as WxH, e.g. 1200x600',) raise self.dpi = rcParams['figure.dpi'] self.xinch = self.width / self.dpi self.yinch = self.height / self.dpi rcParams['figure.figsize'] = (self.xinch, self.yinch) return
def plot_shaded_lines(my_xticks, y1, y2, error1, error2, ylab, xlab, filename): plt.figure(figsize=(6,6)) from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) x = range(0, len(y1)) plt.plot(x, y1, 'k-', color="blue", label='men') plt.fill_between(x, y1-error1, y1+error1, facecolor='blue', alpha=.2) plt.plot(x, y2, 'k-', color="red", label='women') plt.fill_between(x, y2-error2, y2+error2, facecolor='red', alpha=.2) #if isinstance(x, (int, long, float, complex)): # plt.xlim(np.min(x), np.max(x)) plt.gcf().subplots_adjust(bottom=0.3) plt.xticks(x, my_xticks) plt.xticks(rotation=70, fontsize=14) plt.yticks(fontsize=14) #plt.setp(ax.get_xticklabels(), rotation='vertical', fontsize=14) plt.ylabel(ylab, fontsize=14) plt.xlabel(xlab, fontsize=14) plt.legend() plt.savefig(filename)
def make_boxplot_temperature(caObj, name, modis_lvl2=False): low_clouds = get_calipso_low_clouds(caObj) high_clouds = get_calipso_high_clouds(caObj) medium_clouds = get_calipso_medium_clouds(caObj) temp_c = caObj.calipso.all_arrays['layer_top_temperature'][:,0] +273.15 if modis_lvl2: temp_pps = caObj.modis.all_arrays['temperature'] else: temp_pps = caObj.imager.all_arrays['ctth_temperature'] if modis_lvl2: height_pps = caObj.modis.all_arrays['height'] else: height_pps = caObj.imager.all_arrays['ctth_height'] thin = np.logical_and(caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']<0.30, caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']>0) very_thin = np.logical_and(caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']<0.10, caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']>0) thin_top = np.logical_and(caObj.calipso.all_arrays['number_layers_found']>1, thin) thin_1_lay = np.logical_and(caObj.calipso.all_arrays['number_layers_found']==1, thin) use = np.logical_and(temp_pps >100, caObj.calipso.all_arrays['layer_top_altitude'][:,0]>=0) use = np.logical_and(height_pps <45000,use) low = np.logical_and(low_clouds,use) medium = np.logical_and(medium_clouds,use) high = np.logical_and(high_clouds,use) c_all = np.logical_or(high,np.logical_or(low,medium)) high_very_thin = np.logical_and(high, very_thin) high_thin = np.logical_and(high, np.logical_and(~very_thin,thin)) high_thick = np.logical_and(high, ~thin) #print "thin, thick high", np.sum(high_thin), np.sum(high_thick) bias = temp_pps - temp_c abias = np.abs(bias) #abias[abias>2000]=2000 print name.ljust(30, " "), "%3.1f"%(np.mean(abias[c_all])), "%3.1f"%(np.mean(abias[low])),"%3.1f"%(np.mean(abias[medium])),"%3.1f"%(np.mean(abias[high])) c_all = np.logical_or(np.logical_and(~very_thin,high),np.logical_or(low,medium)) number_of = np.sum(c_all) #print name.ljust(30, " "), "%3.1f"%(np.sum(abias[c_all]<250)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<2000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<3000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<4000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<5000)*100.0/number_of) from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) fig = plt.figure(figsize = (6,9)) ax = fig.add_subplot(111) plt.xticks(rotation=70) ax.fill_between(np.arange(0,8),-2.5,2.5, facecolor='green', alpha=0.6) ax.fill_between(np.arange(0,8),-5,5, facecolor='green', alpha=0.4) ax.fill_between(np.arange(0,8),-7.5,7.5, facecolor='green', alpha=0.2) ax.fill_between(np.arange(0,8),10,150, facecolor='red', alpha=0.2) ax.fill_between(np.arange(0,8),-20,-10, facecolor='red', alpha=0.2) for y_val in [-5,-4,-3,-2,-1,1,2,3,4,5]: plt.plot(np.arange(0,8), y_val*20 + 0*np.arange(0,8),':k', alpha=0.4) plt.plot(np.arange(0,8), 0 + 0*np.arange(0,8),':k', alpha=0.4) bplot = ax.boxplot([bias[low],bias[medium],bias[high],bias[high_thick],bias[high_thin],bias[high_very_thin]],whis=[5, 95],sym='', labels=["low","medium","high-all","high-thick\n od>0.4","high-thin \n 0.1<od<0.4","high-vthin\n od<0.1"],showmeans=True, patch_artist=True) ax.set_ylim(-20,100) for box in bplot['boxes']: box.set_facecolor('0.9') plt.title(name) plt.savefig(ADIR + "/PICTURES_FROM_PYTHON/CTTH_BOX/ctth_box_plot_temperature_%s_5_95_filt.png"%(name))
def pdf(params={}, presentation='powerpoint'): if presentation == 'powerpoint': fontsize = 14 figsize = (10,7.5) subplot_left = 0.15 subplot_right = 0.85 subplot_top = 0.8 subplot_bottom = 0.15 if presentation == 'paper': fontsize = 8 figsize = (8,8) subplot_left = 0.2 subplot_right = 0.8 subplot_top = 0.8 subplot_bottom = 0.2 print 'Loading rcparams for saving to PDF' print 'NOTE: ipython plotting may not work as expected with these parameters loaded!' default_params = {'backend': 'Agg', 'ps.usedistiller': 'xpdf', 'ps.fonttype' : 3, 'pdf.fonttype' : 3, 'font.family' : 'sans-serif', 'font.serif' : 'Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman', 'font.sans-serif' : 'Helvetica, Avant Garde, Computer Modern Sans serif', 'font.cursive' : 'Zapf Chancery', 'font.monospace' : 'Courier, Computer Modern Typewriter', 'font.size' : fontsize, 'text.fontsize': fontsize, 'axes.labelsize': fontsize, 'axes.linewidth': 1.0, 'xtick.major.linewidth': 1, 'xtick.minor.linewidth': 1, #'xtick.major.size': 6, #'xtick.minor.size' : 3, 'xtick.labelsize': fontsize, #'ytick.major.size': 6, #'ytick.minor.size' : 3, 'ytick.labelsize': fontsize, 'figure.figsize': figsize, 'figure.dpi' : 72, 'figure.facecolor' : 'white', 'figure.edgecolor' : 'white', 'savefig.dpi' : 300, 'savefig.facecolor' : 'white', 'savefig.edgecolor' : 'white', 'figure.subplot.left': subplot_left, 'figure.subplot.right': subplot_right, 'figure.subplot.bottom': subplot_bottom, 'figure.subplot.top': subplot_top, 'figure.subplot.wspace': 0.2, 'figure.subplot.hspace': 0.2, 'lines.linewidth': 1.0, 'text.usetex': True, } for key, val in params.items(): default_params[key] = val rcParams.update(default_params)
def run_demo(path, ext, seed): from matplotlib import rcParams import numpy.random from mplchaco import mpl2chaco mpldir = os.path.join(path, "mpl") chacodir = os.path.join(path, "chaco") mkdirp(mpldir) mkdirp(chacodir) # like IPython inline plot rcParams.update({ 'figure.figsize': (6.0, 4.0), 'font.size': 10, 'savefig.dpi': 72, 'figure.subplot.bottom': 0.125, }) numpy.random.seed(seed) imgfmt = "{{0}}.{0}".format(ext).format for func in demos: fig = func() cfig = mpl2chaco(fig) dpi = fig.get_dpi() width = fig.get_figwidth() * dpi height = fig.get_figheight() * dpi mplpath = imgfmt(os.path.join(mpldir, func.__name__)) chacopath = imgfmt(os.path.join(chacodir, func.__name__)) fig.savefig(mplpath) save_plot(cfig.plot, chacopath, width, height)
def setFigForm(): """set the rcparams to EmulateApJ columnwidth=245.26 pts """ fig_width_pt = 245.26 * 2 inches_per_pt = 1.0 / 72.27 golden_mean = (math.sqrt(5.0) - 1.0) / 2.0 fig_width = fig_width_pt * inches_per_pt fig_height = fig_width * golden_mean fig_size = [1.5 * fig_width, fig_height] params = { "backend": "ps", "axes.labelsize": 12, "text.fontsize": 12, "legend.fontsize": 7, "xtick.labelsize": 11, "ytick.labelsize": 11, "text.usetex": True, "font.family": "serif", "font.serif": "Times", "image.aspect": "auto", "figure.subplot.left": 0.1, "figure.subplot.bottom": 0.1, "figure.subplot.hspace": 0.25, "figure.figsize": fig_size, } rcParams.update(params)
def plot_TS(temp, psal, depth, lon, lat, svec, tvec, density, title, m, figname): ''' Create the T-S diagram ''' logger = logging.getLogger(__name__) fig = plt.figure(figsize=(15, 15)) rcParams.update({'font.size': 18}) plt.scatter(psal, temp, s=5, c=depth, vmin=10., vmax=1000., edgecolor='None', cmap=plt.cm.plasma) cbar = plt.colorbar(extend='max') plt.xlabel('Salinity', fontsize=18) plt.ylabel('Temperature\n($^{\circ}$C)', rotation=0, ha='right', fontsize=18) cont = plt.contour(svec, tvec, density, levels=np.arange(22., 32., 1.), colors='.65', linestyles='dashed', lineswidth=0.5) plt.clabel(cont,inline=True, fmt='%1.1f') plt.xlim(smin, smax) plt.ylim(tmin, tmax) cbar.set_label('Depth\n(m)', rotation=0, ha='left') plt.grid(color="0.6") # Add an inset showing the positions of the platform inset=plt.axes([0.135, 0.625, 0.3, 0.35]) lon2plot, lat2plot = m(lon, lat) m.drawmapboundary(color='w') m.plot(lon2plot, lat2plot, 'ro', ms=2, markeredgecolor='r') #m.drawcoastlines(linewidth=0.25) m.drawlsmask(land_color='0.4', ocean_color='0.9', lakes=False) plt.title(title, fontsize=20) plt.savefig(figname, dpi=150) # plt.show() plt.close()
def myScatter(lst,xtxt="",ytxt="",f="out.pdf"): import matplotlib import matplotlib.pyplot as plt from matplotlib.backends.backend_agg \ import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import numpy from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) asnum = numpy.array x,y = asnum([z[0] for z in lst]), \ asnum([z[1] for z in lst]) fig = Figure(figsize=(4,2)) canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.set_xlabel(xtxt,fontsize=9) ax.set_ylabel(ytxt,fontsize=9) ax.grid(True,linestyle='-',color='0.75') ax.set_ylim((-2,102)) cm = plt.cm.get_cmap('RdYlGn') plt.ylim(-5,100) ax.plot(x,y,marker='o', linestyle='--', color='r', label='Square') ax.tick_params(axis='both', which='major', labelsize=9) ax.tick_params(axis='both', which='minor', labelsize=9) print(f) canvas.print_figure(f,dpi=500)
def valueOccurenceGraphInverse(nameDict, height): valueOps = [nameDict[name].opAtHeight(height) for name in nameDict] values = [x.value for x in valueOps if x is not None] counter = collections.Counter(values) prevCount = 0 maxValues = len(values) total = len(values) xData = [] yData = [] for value, count in reversed(counter.most_common()): if count > prevCount: xData.append(prevCount) yData.append(total/maxValues) for i in range(prevCount + 1, count): xData.append(i) yData.append(total/maxValues) total -= count prevCount = count xData.append(count) yData.append(total) ax = plt.subplot(111) plt.plot(xData, yData) ax.set_xlim([-300,20000]) formatter = FuncFormatter(to_percent) plt.gca().yaxis.set_major_formatter(formatter) plt.xlabel(r"\textbf{Value occurs more than n times}") plt.ylabel(r"\textbf{Percent of total names}") rc('font', serif='Helvetica Neue') rc('text', usetex='true') rcParams.update({'font.size': 16}) rcParams.update({'figure.autolayout': True})
def create_graph_multiple_time_value(xs, ys, keys, title, x_label, y_label, outFile): markers = ['.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', '8', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_'] rcParams.update({'figure.autolayout': True}) pp = PdfPages(outFile) f = plt.figure() ax = plt.gca() marker_i = 0 for key in keys: plt.plot(xs[key], ys[key], label=key, marker=markers[marker_i]) marker_i = (marker_i + 1) % len(markers) plt.xlabel(x_label) plt.ylabel(y_label) plt.title(title) plt.grid(True) plt.legend(loc='best') ymin, ymax = plt.ylim() plt.ylim(0, ymax) plt.close() pp.savefig(f) pp.close() return
def plotY1Y2(points, title="Estimate vs. Workers", xaxis="# Workers", yaxis="Estimate", legend=[], filename="output.png"): import matplotlib.pyplot as plt from matplotlib import font_manager, rcParams rcParams.update({'figure.autolayout': True}) rcParams.update({'font.size': 16}) fprop = font_manager.FontProperties(fname= '/Library/Fonts/Microsoft/Gill Sans MT.ttf') num_estimators = len(points[1][0]) plt.figure() colors = ['#00ff99','#0099ff','#ffcc00','#ff5050'] for i in range(0,num_estimators): res = [j[i] for j in points[1]] plt.plot(points[0], res, 's-', linewidth=2.5,markersize=7,color=colors[i]) #plt.plot(points[0], points[2], 'o-', linewidth=2.5,markersize=5,color='#FF6666') plt.plot(points[0], points[2], '--', linewidth=2.5,color='#333333') plt.title(title,fontproperties=fprop) plt.xlabel(xaxis,fontproperties=fprop) plt.ylabel(yaxis,fontproperties=fprop) plt.ylim(ymin=0) plt.xlim(xmin=points[0][0], xmax=points[0][len(points[0])-1]) plt.legend(legend,loc='lower right') plt.grid(True) plt.savefig(filename,bbox_inches='tight')
def latexify(fig_width='revtex4', aspect=0.75): """ Prepare publication quality plots. Parameters ---------- fig_width : str or float a latex class or the width of the figure in pt aspect : float aspect ratio of figures Notes ----- Based on http://nipunbatra.github.io/2014/08/latexify/. """ if fig_width=='revtex4': fig_width = 246.0 / 72 fig_height = fig_width * aspect params = {'axes.labelsize': 8, 'axes.titlesize': 8, 'font.size': 8, 'legend.fontsize': 8, 'xtick.labelsize': 8, 'ytick.labelsize': 8, 'lines.linewidth': 0.5, 'axes.linewidth': 0.5, 'lines.linewidth': 0.5, 'patch.linewidth': 0.5, 'figure.figsize': [fig_width, fig_height], 'figure.dpi': 160, 'lines.markersize': 3} rcParams.update(params) return rcParams
def create_graph_multiple_time_value_log_paper_version(xs, ys, keys, sorting_orders, legend_entries, x_label, y_label, outFile): markers = ['.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', '8', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_'] rcParams.update({'figure.autolayout': True}) pp = PdfPages(outFile) f = plt.figure() f.set_size_inches(6.88, 5.4) ax = plt.gca() marker_i = 0 for key in keys: plt.plot(itemgetter(*sorting_orders[key])(xs[key]), itemgetter(*sorting_orders[key])(ys[key]), label=legend_entries[key]) # , marker=markers[marker_i] marker_i = (marker_i + 1) % len(markers) plt.xlabel(x_label) plt.ylabel(y_label) ax.set_yscale('log') plt.grid(True) plt.legend(loc='best') ymin, ymax = plt.ylim() # plt.ylim(0, ymax) plt.close() pp.savefig(f) pp.close() return
def plotV(Sall): params = { 'axes.labelsize': 10, 'font.size': 10, 'legend.fontsize': 10, 'xtick.labelsize': 10, 'ytick.labelsize': 10, 'text.usetex': False, 'figure.figsize': [3.8, 3.8], } rcParams.update(params) for i in range(Sall.secNum): h1, = plot(Sall.S[i], Sall.V[i]*3.6, color="black", linewidth=1) #, label=u'速度曲线' h2, = plot(Sall.S[i], [Sall.secLimit[i]*3.6]*len(Sall.S[i]), color="black", linewidth=1, linestyle="--") ylim(0.0,100.0) xlim(12100, 13600) gca().invert_xaxis() xlabel('公里标(m)') ylabel('速度(m/s)') h1._label = "速度曲线" h2._label = "速度限制" legend(loc='upper right') savefig("S6.pdf", dpi=600) show()
def test_colorbar_extension_shape(): '''Test rectangular colorbar extensions.''' # Use default params so matplotlibrc doesn't cause the test to fail. rcParams.update(rcParamsDefault) # Create figures for uniform and proportionally spaced colorbars. fig1 = _colorbar_extension_shape('uniform') fig2 = _colorbar_extension_shape('proportional')
def temporal_analysis(): words = ["sorto", u"ryssä", "nais", "torppar", u"työttömy", "nykyi", "histor", "jumala", "kirkko", "jeesus", u"marx", u"sosialis", u"porwari", u"työ", u"työttömyy", u"työläi", u"työvä", u"kapitalis", u"taantu", u"taistel", u"toveri", u"vallankumou", "torppari", "agitaattori", u"köyhälistö", u"kärsi", "orja", "sort", "sosialidemokraatti", "lakko", "vapau", "voitto"] ts, soc_freqs, other_freqs = frequency_over_time(words) print 100000 * soc_freqs print 100000 * other_freqs from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) for i, word in enumerate(words): plt.figure(1) plt.clf() plt.plot(ts[:-1], soc_freqs[:,i], '-x') plt.plot(ts[:-1], other_freqs[:,i], '-o') max_y = max(np.max(soc_freqs[:,i]), np.max(other_freqs[:,i])) plt.ylim((0, max_y*1.05)) plt.xlabel('Year') plt.ylabel('Frequency') plt.title(word) plt.legend(['Socialist', 'Others'], loc='best') plt.savefig('../plots/%s.png' % word) date_str = re.sub(" ", "T", str(dt.datetime.now()))[:-7] date_str = re.sub(":", "", date_str) pickle.dump((ts,soc_freqs,other_freqs,words), open('../plot_data/%s.pckl' % date_str, 'wb')) save_csv2(words, soc_freqs, ts, "socialist") save_csv2(words, other_freqs, ts, "others") save_csv(words, soc_freqs, "socialist") save_csv(words, other_freqs, "others")
def test_configure_mpl(): plot.configure_mpl() assert os.environ['HOME'] == os.environ['MPLCONFIGDIR'] assert rcParams['ps.useafm'] is True assert rcParams['pdf.use14corefonts'] is True assert rcParams['text.usetex'] is True rcParams.update(rcParamsDefault)
def local_init(): global nars global qh matplotlib.style.use('ggplot') mp_rc.update({'figure.autolayout': True}) u.reload_window() nars = Nars.Nars(survey, survey_data) qh = QH.QHelpers(q, survey_data)
def use(name): context = rc_context() try: rcParams.update(STYLE_FUNCTIONS[name]()) except: context.__exit__(*sys.exc_info()) raise return context
def __init__(self, rc=None, fname=None): self.rcdict = rc self.fname = fname self._rcparams = rcParams.copy() if self.fname: rc_file(self.fname) if self.rcdict: rcParams.update(self.rcdict)
def plot(results, skipAlgs=[]): import matplotlib.pyplot as plt from matplotlib import rcParams import numpy as np import math rcParams.update({'font.size': 18}) binSize = 5 for i, (fn, fnResults) in enumerate(results.items()): plt.figure(i) for alg, algResults in fnResults.items(): if alg in skipAlgs: continue if 'TrueOptima' in algResults: trueOptima = algResults['TrueOptima'] errorBins = dict() # Find a list of the means of each run for run in algResults['Runs']: runErrorBins = dict() costs = np.array(run['Costs']).flatten() if 'Errors' in run: errors = np.array(run['Errors']).flatten() elif 'Values' in run: errors = trueOptima - np.array(run['Values']) for c, e in zip(costs, errors): _bin = math.floor(c / binSize) * binSize if _bin not in runErrorBins: runErrorBins[_bin] = [e] else: runErrorBins[_bin].append(e) # Get the mean errors of the run for _bin, es in runErrorBins.items(): if _bin not in errorBins: errorBins[_bin] = [np.mean(es)] else: errorBins[_bin].append(np.mean(es)) costValues = list(errorBins.keys()) errorValues = list(errorBins.values()) perm = np.argsort(costValues) costValues = np.array(costValues)[perm] errorValues = np.array(errorValues)[perm] means = np.array([np.mean(es) for es in errorValues]) lows = np.array([np.min(es) for es in errorValues]) highs = np.array([np.max(es) for es in errorValues]) plt.plot(costValues, means, label=alg) if alg == 'MF-BaMLOGO': alpha = 0.5 else: alpha = 0.1 plt.fill_between(costValues, lows, highs, alpha=alpha) plt.legend() plt.title(fn) plt.xlabel('Cumulative Cost') plt.ylabel('Simple Regret (log scale)') plt.yscale('log') plt.show()
def plotY1Y2(points, title="", xaxis="# Workers", yaxis="Estimate", ymax=-1, legend=[], legend_gt=[], loc = 'upper right', filename="output.png", logscale=False, ): #import matplotlib as mpl #mpl.use('Agg') #import matplotlib.pyplot as plt from matplotlib import font_manager, rcParams rcParams.update({'figure.autolayout': True}) rcParams.update({'font.size': 15}) fprop = font_manager.FontProperties(fname='/Library/Fonts/Microsoft/Gill Sans MT.ttf') num_estimators = len(points[1][0]) num_gt = len(legend_gt)#len(points[2][0]) plt.figure() colors = ['#00ff99','#0099ff','#ffcc00','#ff5050','#9900cc','#5050ff','#99cccc','#0de4f6'] markers = ['o-','v-','^-','s-','*-','x-','+-','D-'] shapes = ['--','-*'] for i in range(0,num_gt): res = [j[i] for j in points[2]] if logscale: plt.semilogy(points[0], res, shape[i],linewidth=2.5,color="#333333") else: plt.plot(points[0], res, shapes[i],linewidth=2.5,color="#333333") for i in range(0,num_estimators): res = [j[i] for j in points[1]] if logscale: plt.semilogy(points[0], res, 's-', linewidth=2.5, markersize=7, color=colors[i]) else: plt.plot(points[0], res, markers[i], linewidth=2.5,markersize=7,color=colors[i]) #plt.plot(points[[lookup_tbl[(pair_resp[0][1],pair_resp[0][0])],ilist_workers.index(k)] = pair_resp[1] #plt.plot(points[0], points[2], '--', linewidth=2.5,color='#333333') plt.title(title) plt.xlabel(xaxis)#,fontproperties=fprop) plt.ylabel(yaxis)#,fontproperties=fprop) if not logscale and ymax == -1: plt.ylim(ymin=0) elif not logscale: plt.ylim(ymin=0,ymax=ymax) print num_gt + num_estimators, legend_gt + legend plt.xlim(xmin=points[0][0], xmax=points[0][len(points[0])-1]) plt.legend(legend_gt+legend,loc=loc) plt.grid(True) plt.savefig(filename,bbox_inches='tight')#,format='pdf')
# -*- coding: utf-8 -*- from matplotlib import pyplot as plt from numpy import genfromtxt,unique,zeros,where,array,nan from matplotlib import rcParams etaclip=50 rcParams.update({'font.size': 22}) fgmax_file=u'/Users/dmelgar/Tsunamis/Cascadia/fort.FG1.valuemax' aux_file='/Users/dmelgar/Tsunamis/Cascadia/fort.FG1.aux1' wet_tol=0.001 etaclip=50 #Get maximum amplitude first lon=genfromtxt(fgmax_file,usecols=0) lat=genfromtxt(fgmax_file,usecols=1) amr=genfromtxt(fgmax_file,usecols=2) H_in=genfromtxt(fgmax_file,usecols=3) b_in=genfromtxt(aux_file) unique_amr=unique(amr) eta=zeros(len(H_in)) H=zeros(len(H_in)) b=zeros(len(H_in)) for k in range(len(unique_amr)): i=where(amr==unique_amr[k])[0] if unique_amr[k]==0: eta[i]=0 else: eta[i]=H_in[i]+b_in[i,unique_amr[k]+1]
import numpy as np import matplotlib.pyplot as plt from matplotlib import rcParams from scipy.special import logsumexp fontparams = { 'mathtext.fontset': 'stix', 'font.family': 'serif', 'font.serif': "Times New Roman", 'mathtext.rm': "Times New Roman", 'mathtext.it': "Times New Roman:italic", 'mathtext.sf': 'Times New Roman', 'mathtext.tt': 'Times New Roman' } rcParams.update(fontparams) # Set up the argument parser parser = argparse.ArgumentParser( "Rebuild the eccentricity distribution based on weights given in output files" ) parser.add_argument("-r", "--results-folder", help="Location of the results files") args = parser.parse_args() result_files = list( glob.glob(args.results_folder + '/result_*_master_output_store.txt')) eccentricities = [] log_weights = []
locale.setlocale(locale.LC_ALL, '') import os from copy import deepcopy from datetime import datetime import shutil import numpy as np import math import sympy as smp import matplotlib as mpl from matplotlib import pyplot as plt, rcParams, ticker from mpl_toolkits.mplot3d import Axes3D from matplotlib.colors import to_rgb rcParams['axes.formatter.use_locale'] = True rcParams.update({'font.family':'serif', 'mathtext.fontset': 'dejavuserif', 'font.size': 14, 'axes.titlesize' : 14}) np.set_printoptions(precision=4) IS_SHOW_GRAF = True DIRECT_PATH = r'C:\Users\ichet\Dropbox\myDocs\St\bd_tepl' try: # Спочатку видаляється папка. shutil.rmtree(DIRECT_PATH) except FileNotFoundError: pass os.mkdir(DIRECT_PATH) # Потім створюється папка. v = 4.2 alpha_v = 8.7 A_t_z = 19.3 rho = .7
obj_lines['SHOC579'][r'$[OII]3729\AA$'] = 3728.0 obj_lines['SHOC579'][r'$H\delta$'] = 4101.68 obj_lines['SHOC579'][r'$HeI4026\AA$'] = 4026.68 obj_lines['SHOC579'].update(obj_lines['8']) ak = lineid_plot.initial_annotate_kwargs() # ak['arrowprops']['arrowstyle'] = "->" ak['arrowprops']['relpos'] = (0.5, 0.0) ak['rotation'] = 90 pk = lineid_plot.initial_plot_kwargs() pk['linewidth'] = 0.5 factor_norm = 1e-15 rcParams.update(size_dict) fig = plt.figure() format_plot = {'8': {}, 'SHOC579': {}} format_plot['8']['xlims'] = {'left': 4300, 'right': 9800} format_plot['SHOC579']['xlims'] = {'left': 3500, 'right': 9800} format_plot['8']['ylims'] = { 'bottom': -2e-16 / factor_norm, 'top': 3.5e-15 / factor_norm } format_plot['SHOC579']['ylims'] = { 'bottom': -2e-16 / factor_norm, 'top': 3e-15 / factor_norm } format_plot['8']['OffsetImage'] = {'zoom': 0.25}
import numpy as np import matplotlib.pyplot as plt import seaborn as sns # improves plot aesthetics import pandas as pd from ast import literal_eval as make_tuple from matplotlib import colors as mcolors import matplotlib.patches as mpatches from matplotlib import rcParams import os rcParams.update({'figure.autolayout': True}) plotall_inone = False def _invert(x, limits): """inverts a value x on a scale from limits[0] to limits[1]""" return limits[1] - (x - limits[0]) def _scale_data(data, ranges): """scales data[1:] to ranges[0], inverts if the scale is reversed""" for d, (y1, y2) in zip(data[1:], ranges[1:]): assert (y1 <= d <= y2) or (y2 <= d <= y1) x1, x2 = ranges[0] d = data[0] if x1 > x2: d = _invert(d, (x1, x2)) x1, x2 = x2, x1 sdata = [d]
def MRG_vs_CLNumber(dimension, monomerNumber, b, keepCL, simulationParams, test_connectorsNumber, test_genomic_distances, errorbars): """ Main function """ # Output file output = np.zeros( (len(test_genomic_distances), 3, len(test_connectorsNumber))) date = strftime("%Y_%m_%d_%H_%M") plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) plt.xlabel("Number of cross-links") plt.ylabel("Mean radius of gyration ($\mu$m)") for i, genomicDistance in enumerate(test_genomic_distances): MRG = [] demiCI = [] for Nc in test_connectorsNumber: p0 = RCLPolymer(monomerNumber, dimension, b, Nc, keepCL) results = {} simulationParams['genomicDistance'] = genomicDistance mc = Experiment(p0, results, simulationParams, "twoDSB") MRG.append(mc.results['MSRG']) demiCI.append(mc.results['MSRG_95CI']) MRG = np.array(MRG) demiCI = np.array(demiCI) output[i][0] = test_connectorsNumber output[i][1] = np.sqrt(MRG) output[i][2] = demiCI np.save( 'results/MRG_vs_conectorsNumber__' + 'keepCL_' + str(keepCL) + str(monomerNumber) + 'monomers_' + str(simulationParams['numRealisations']) + 'iterations' + date + '.npy', output) if errorbars: plt.errorbar(x=test_connectorsNumber, y=np.sqrt(MRG), yerr=demiCI, fmt='-o', label=r'$g = $ ' + str(genomicDistance), capsize=4) else: plt.plot(test_connectorsNumber, MRG, '-o', label=r'$g = $ ' + str(genomicDistance)) np.save( 'results/MRG_vs_conectorsNumber__' + 'keepCL_' + str(keepCL) + str(monomerNumber) + 'monomers_' + str(simulationParams['numRealisations']) + 'iterations' + date + '.npy', output) plt.legend() plt.show() return output
from matplotlib import cm nice_fonts = { # Use LaTeX to write all text #"text.usetex": True, "font.family": "serif", # Use 10pt font in plots, to match 10pt font in document "axes.labelsize": 14, "font.size": 12, # Make the legend/label fonts a little smaller "legend.fontsize": 12, "xtick.labelsize": 12, "ytick.labelsize": 12, } rcParams.update(nice_fonts) class Detector: def __init__(self, absorber, QET, n_channel=1, w_rail_main=6e-6, w_railQET=4e-6, bonding_pad_area=4.5e-8, freqs=None, passive=1, equal_spaced=True,
""" import matplotlib import matplotlib.pyplot as plt import numpy as np import os from scipy.stats import norm, zscore, kstest, pearsonr import pandas as pd from skimage import io import seaborn as sns from neuprint import (fetch_neurons, NeuronCriteria, Client) from skimage.filters import gaussian from scfc import bridge, anatomical_connectivity from matplotlib import rcParams rcParams.update({'font.size': 10}) rcParams.update({'figure.autolayout': True}) rcParams.update({'axes.spines.right': False}) rcParams.update({'axes.spines.top': False}) rcParams['svg.fonttype'] = 'none' # let illustrator handle the font type data_dir = bridge.getUserConfiguration()['data_dir'] analysis_dir = bridge.getUserConfiguration()['analysis_dir'] plot_colors = plt.get_cmap('tab10')(np.arange(8)/8) save_dpi = 400 # %% ~Lognormal distribtution of connection strengths include_inds_ito, name_list_ito = bridge.getItoNames() ConnectivityCount = anatomical_connectivity.getAtlasConnectivity(include_inds_ito, name_list_ito, 'ito', metric='cellcount') ConnectivityTBars = anatomical_connectivity.getAtlasConnectivity(include_inds_ito, name_list_ito, 'ito', metric='tbar')
from matplotlib import rcParams dir_path = os.path.dirname(os.path.realpath(__file__)) # from mpl_toolkits.mplot3d.axes3d import get_test_data def grid_color(n): if n == 0: color = 'black' else: color = 'cornflowerblue' return color rcParams.update({ "font.family": "sans-serif", "font.sans-serif": ["Arial"], }) basis1 = np.array([[1,0], [0,1]]) basis2 = np.array([[1, 0], [1, 1]]) bases = [basis1, basis2] colors = ['red', 'blue'] vecComp = np.array([1,2]) arrow_kw = {'head_width': 0.1, 'head_length': 0.2, 'width': 0.02, 'length_includes_head': True} text_kw = dict(fontsize=14) # set up a figure twice as wide as it is tall fig, ax = plt.subplots(1, 1, figsize=(3,3)) fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) rangeX = (-1, 4)
os.chdir(ppdpath) allfitsname = glob.glob('*.fits') allfitspath = list(ppdpath.glob('*.fits')) allfitspath.sort() allfitsname.sort() print(len(allfitspath), "Items are searched") #%% images = [] #%% DISPAXIS = 2 # 1 = line = python_axis_1 // 2 = column = python_axis_0 FONTSIZE = 12 # Change it on your computer if you wish. rcParams.update({'font.size': FONTSIZE}) COMPIMAGE = os.path.join(ppdpath, 'Comp-master.fits') # Change directory if needed! OBJIMAGE = os.path.join(newfitspath, 'HD207673-0001.fits') LINE_FITTER = LevMarLSQFitter() #%% lamphdu = fits.open(COMPIMAGE) objhdu = fits.open(OBJIMAGE) lampimage = lamphdu[0].data objimage = objhdu[0].data if lampimage.shape != objimage.shape: raise ValueError('lamp and obj images should have same sizes!') if DISPAXIS == 2:
def performance_analysis(self, X_test, y_test, file_name="", verbose=True, confusion_matrix=True, plotting_confusion_matrix=True, classification_report=True, save_pred=True): y_pred = self.predict(X_test) metric_list = list() with open('results/{}.txt'.format(file_name), 'w', encoding="utf-8") as f: if (confusion_matrix): confusion_matrix = metrics.confusion_matrix( y_test, y_pred, labels=["positive", "neutral", "negative"]) metric_list.append(confusion_matrix) if (verbose): print("confusion matrix:", file=f) print(confusion_matrix, file=f) if (plotting_confusion_matrix): from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) # plot confusion matrix plt.figure(dpi=600) plot_confusion_matrix( confusion_matrix, classes=['positiv', 'neutral', 'negativ'], title='Wahrheitsmatrix') plt.savefig( 'results/{}_confusion_matrix_1.png'.format(file_name)) # plot normalized confusion matrix plt.figure(dpi=600) plot_confusion_matrix( confusion_matrix, classes=['positiv', 'neutral', 'negativ'], normalize=True, title='normalisierte Wahrheitsmatrix') plt.savefig( 'results/{}_confusion_matrix_2.png'.format(file_name)) if (classification_report): classification_report = metrics.classification_report( y_test, y_pred) metric_list.append(classification_report) if (verbose): print("classification report:", file=f) print(classification_report, file=f) if (save_pred): with open( 'results/predictions/{}_predictions.txt'.format(file_name), 'w', encoding="utf-8") as f: for i in range(len(y_pred)): print("{}\t{}".format(y_pred[i], X_test[i]), file=f) return metric_list
import matplotlib.pyplot as plt from matplotlib import rcParams import pickle import os import json from libs.train import rec_mkdir from libs import config PREFERENCE = { "font.family": 'serif', "mathtext.fontset": 'stix', "font.serif": ['SimSun'], "axes.unicode_minus": False } rcParams.update(PREFERENCE) class LoadTestData(object): """加载测试数据""" def __init__(self, **kwargs): """ Parameter: self.dtype - 加载的数据类型,net为神经网络模型测试数据,cs为压缩感知测试数据 self.velocity - 选择的速度 self.ratio_list - 选择的压缩率列表 """ for key, value in kwargs.items(): setattr(self, key, value)
formatter = logging.Formatter( "%(asctime)s::%(levelname)s::%(module)s::%(message)s", "%Y-%m-%d %H:%M:%S") ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(formatter) logger.addHandler(ch) logger.info('import ok') font_spec = { 'font.family': 'sans-serif', 'font.sans-serif': ['Fira Sans'], 'font.weight': 'regular' } rcParams.update(font_spec) logger.info('matplotlib ok') prj_string_file = Path("data/aachen_net/aachen_district_map_prj.txt") if not prj_string_file.is_file(): import osr # troublesome to install in cluster prj_content = open('data/aachen_net/aachen_district_map.prj', 'r').read() srs = osr.SpatialReference() srs.ImportFromWkt(prj_content) with open(str(prj_string_file), 'w') as f: f.write(srs.ExportToProj4()) prj_string = open(str(prj_string_file), 'r').read() projection = Proj(prj_string)
def MSRG_vs_CLremoval(dimension, monomerNumber, b, keepCL, simulationParams, test_connectorsNumber, test_genomic_distances, errorbars): """ Main function """ # Output file genomic_distance = test_genomic_distances[-1] simulationParams['genomicDistance'] = genomic_distance date = strftime("%Y_%m_%d_%H_%M") output = np.zeros((2, 3, len(test_connectorsNumber))) plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) plt.xlabel('Number of random cross-links') plt.ylabel(r'Mean radius of gyration ($\mu$m)') for i, keepCL in enumerate([True, False]): MRG = [] demiCI = [] for Nc in test_connectorsNumber: p0 = RCLPolymer(monomerNumber, dimension, b, Nc, keepCL) results = {} mc = Experiment(p0, results, simulationParams, "twoDSB") MRG.append(mc.results['MSRG']) demiCI.append(mc.results['MSRG_95CI']) MRG = np.array(MRG) demiCI = np.array(demiCI) output[i][0] = test_connectorsNumber output[i][1] = np.sqrt(MRG) output[i][2] = demiCI if keepCL: labelExp = "Keeping RCLs" else: labelExp = "Removing RCLs" if errorbars: plt.errorbar(x=test_connectorsNumber, y=MRG, yerr=demiCI, fmt='-o', label=labelExp, capsize=4) else: plt.plot(test_connectorsNumber, MRG, '-o', label=labelExp) np.save( 'results/MSRG_vs_RCLremoval__' + str(monomerNumber) + 'monomers_' + str(genomic_distance) + 'genomicDistance_' + str(simulationParams['numRealisations']) + 'iterations' + date + '.npy', output) plt.legend(fontsize='xx-large') plt.show()
def create(path: str, name: str, header: dict, traces: List[Trace], old_style: bool = False) -> Figure: rcParams.update({'font.size': 9}) log.info('Making PID plot...') fig = plt.figure('Response plot: Log number: ' + header['logNum'] + ' ' + path, figsize=(16, 8)) # gridspec devides window into 24 horizontal, 3*10 vertical fields gs1 = GridSpec(24, 3 * 10, wspace=0.6, hspace=0.7, left=0.04, right=1., bottom=0.05, top=0.97) for i, trace in enumerate(traces): ax0 = plt.subplot(gs1[0:6, i * 10:i * 10 + 9]) plt.title(trace.name) plt.plot(trace.time, trace.gyro, label=trace.name + ' gyro') plt.plot(trace.time, trace.input, label=trace.name + ' loop input') plt.ylabel('degrees/second') ax0.get_yaxis().set_label_coords(-0.1, 0.5) plt.grid() tracelim = np.max([np.abs(trace.gyro), np.abs(trace.input)]) plt.ylim([-tracelim * 1.1, tracelim * 1.1]) plt.legend(loc=1) plt.setp(ax0.get_xticklabels(), visible=False) ax1 = plt.subplot(gs1[6:8, i * 10:i * 10 + 9], sharex=ax0) plt.hlines(header['tpa_percent'], trace.time[0], trace.time[-1], label='tpa', colors='red', alpha=0.5) plt.fill_between(trace.time, 0., trace.throttle, label='throttle', color='grey', alpha=0.2) plt.ylabel('throttle %') ax1.get_yaxis().set_label_coords(-0.1, 0.5) plt.grid() plt.xlim([trace.time[0], trace.time[-1]]) plt.ylim([0, 100]) plt.legend(loc=1) plt.xlabel('log time in s') if old_style: # response vs. time in color plot plt.setp(ax1.get_xticklabels(), visible=False) ax2 = plt.subplot(gs1[9:16, i * 10:i * 10 + 9], sharex=ax0) plt.pcolormesh(trace.avr_t, trace.time_resp, np.transpose(trace.spec_sm), vmin=0, vmax=2.) plt.ylabel('response time in s') ax2.get_yaxis().set_label_coords(-0.1, 0.5) plt.xlabel('log time in s') plt.xlim([trace.avr_t[0], trace.avr_t[-1]]) else: # response vs throttle plot. more useful. ax2 = plt.subplot(gs1[9:16, i * 10:i * 10 + 9]) plt.title(trace.name + ' response', y=0.88, color='w') plt.pcolormesh(trace.thr_response['throt_scale'], trace.time_resp, trace.thr_response['hist2d_norm'], vmin=0., vmax=2.) plt.ylabel('response time in s') ax2.get_yaxis().set_label_coords(-0.1, 0.5) plt.xlabel('throttle in %') plt.xlim([0., 100.]) cmap = plt.cm.get_cmap('Blues') cmap._init() alphas = np.abs(np.linspace(0., 0.5, cmap.N, dtype=np.float64)) cmap._lut[:-3, -1] = alphas ax3 = plt.subplot(gs1[17:, i * 10:i * 10 + 9]) plt.contourf(*trace.resp_low[2], cmap=cmap, linestyles=None, antialiased=True, levels=np.linspace(0, 1, 20, dtype=np.float64)) plt.plot(trace.time_resp, trace.resp_low[0], label=trace.name + ' step response ' + '(<' + str(int(Trace.threshold)) + ') ' + ' PID ' + header[trace.name + 'PID']) if trace.high_mask.sum() > 0: cmap = plt.cm.get_cmap('Oranges') cmap._init() alphas = np.abs(np.linspace(0., 0.5, cmap.N, dtype=np.float64)) cmap._lut[:-3, -1] = alphas plt.contourf(*trace.resp_high[2], cmap=cmap, linestyles=None, antialiased=True, levels=np.linspace(0, 1, 20, dtype=np.float64)) plt.plot(trace.time_resp, trace.resp_high[0], label=trace.name + ' step response ' + '(>' + str(int(Trace.threshold)) + ') ' + ' PID ' + header[trace.name + 'PID']) plt.xlim([-0.001, 0.501]) plt.legend(loc=1) plt.ylim([0., 2]) plt.ylabel('strength') ax3.get_yaxis().set_label_coords(-0.1, 0.5) plt.xlabel('response time in s') plt.grid() meanfreq = 1. / (traces[0].time[1] - traces[0].time[0]) ax4 = plt.subplot(gs1[12, -1]) t = BANNER + " | Betaflight: Version " + header['version'] + ' | Craftname: ' + header[ 'craftName'] + \ ' | meanFreq: ' + str(int(meanfreq)) + ' | rcRate/Expo: ' + header['rcRate'] + '/' + header[ 'rcExpo'] + '\nrcYawRate/Expo: ' + header['rcYawRate'] + '/' \ + header['rcYawExpo'] + ' | deadBand: ' + header['deadBand'] + ' | yawDeadBand: ' + \ header['yawDeadBand'] \ + ' | Throttle min/tpa/max: ' + header['minThrottle'] + '/' + header['tpa_breakpoint'] + '/' + \ header['maxThrottle'] \ + ' | dynThrPID: ' + header['dynThrottle'] + '| D-TermSP: ' + header[ 'dTermSetPoint'] + '| vbatComp: ' + header['vbatComp'] plt.text(0, 0, t, ha='left', va='center', rotation=90, color='grey', alpha=0.5, fontsize=TEXTSIZE) ax4.axis('off') log.info('Saving as image...') plt.savefig(path[:-13] + name + '_' + str(header['logNum']) + '_response.png') return fig
import pandas as pd from scipy.stats import ranksums import matplotlib.pyplot as plt import seaborn as sns sns.set_style('whitegrid') from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) rcParams.update({'font.size': 12}) from textwrap import fill from scipy.stats import ranksums if __name__ == '__main__': exposure_df = pd.read_csv(snakemake.input[0], sep="\t", index_col=0) feature_df = pd.read_csv(snakemake.input[1], sep="\t", index_col=0) df = exposure_df.merge(feature_df, left_index=True, right_index=True) topic = snakemake.wildcards["topic"] feature=snakemake.wildcards["feature"] ax = sns.swarmplot(x=feature, y=topic, data=df) # plt.legend() plt.legend(ncol=1, loc='upper center') ax = sns.boxplot(x=feature, y=topic, data=df, showcaps=False, boxprops={'facecolor':'None'}, showfliers=False, whiskerprops={'linewidth':0}) #ax.set_xlabel('Held-out Samples') # plt.show() plt.savefig(snakemake.output[0])
# Calculates the density using the density output files from ArcPIC2D. # These gives the density at gridpoints using the Verbonceur volumes, # averaged over n_ave_time steps. # import sys, os, shutil import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import Normalize, LogNorm from matplotlib.ticker import LogFormatter, LogLocator, MaxNLocator import matplotlib.colorbar as colorbar from matplotlib import gridspec from matplotlib import rcParams, rc rcParams.update({'text.usetex': True}) #slow DPI = 500 #Get input if len(sys.argv) < 5 or len(sys.argv) > 8: print "Usage: ./2Dpic_density_densfiles.py <mintime> <maxtime> <every nth frame to analyse> <{e|Cu|Cup|qdens|all|all2|allRow}> {<axisShape='square'|'image'>} {<FPS=5>} {cutR=MAX|number}" exit(1) mintime = int(sys.argv[1]) maxtime = int(sys.argv[2]) skipFrame = int(sys.argv[3]) species = sys.argv[4] if not (species == "e" or species == "Cu" or species == "Cup" or species == "qdens" or species == "all" or species == "all2" or species == "allRow"):
import numpy as np import matplotlib.pyplot as plt from matplotlib import rcParams from HITpost import HITpost rcParams['text.usetex'] = True rcParams['axes.labelsize'] = 18 rcParams['xtick.labelsize'] = 14 rcParams['ytick.labelsize'] = 14 rcParams['axes.linewidth'] = 1.4 params = {'text.latex.preamble': [r'\usepackage{sfmath}']} rcParams.update(params) plt.rc('text', usetex=True) plt.rc('font', family='sans-serif') nRlz = 2 drc0 = '../../rC_HIT/' psF0 = HITpost(drc0) psF0.createGasPhase() psF0.gas.postProc(nRlz) psF0.gas.energSpect(1001, nRlz) k0 = psF0.gas.k ep0 = psF0.gas.d nu0 = psF0.gas.visc print('#### Input ####') print('Density: ' + str(psF0.gas.rho)) print('Viscosity: ' + str(psF0.gas.visc)) print('Shear Rate: ' + str(psF0.gas.Srate))
# (c) 2017 Gregor Mitscha-Baude import numpy as np import folders fields = folders.fields from nanopores.models.nanopore import IV from collections import OrderedDict from matplotlib import rcParams, rc rcParams.update({ "font.size": 7, "axes.titlesize": 7, "font.family": "sans-serif", "font.sans-serif": ["CMU Sans Serif"], "lines.linewidth": 1, "lines.markersize": 5, }) from matplotlib import pyplot as plt ddsimplerough = dict(name="Dalphahem", dim=2, Nmax=.1e5, h=1., ahemqsuniform=True, rMolecule=0.11) ddsimplefine = dict(name="Dalphahem", dim=2, Nmax=1e5, h=.5, ahemqsuniform=True, rMolecule=0.11)
def ts_plot(self, **kwargs): """ Plots timeseries in matplotlib plot Parameters ---------- traces: dict Data for the plot, with the format: "traces": {"1": {"devices": ['8019043', '8019044', '8019004'], "channel" : "PM_10", "subplot": 1, "extras": ['max', 'min', 'avg']}, "2": {"devices": "all", "channel" : "TEMP", "subplot": 2} } options: dict Options including data processing prior to plot. Defaults in config.plot_def_opt formatting: dict Formatting dict. Defaults in config.ts_plot_def_fmt Returns ------- Matplotlib figure """ if config.framework == 'jupyterlab': plt.ioff() plt.clf() if 'traces' not in kwargs: std_out('No traces defined', 'ERROR') return None else: traces = kwargs['traces'] if 'options' not in kwargs: std_out('Using default options') options = config.plot_def_opt else: options = dict_fmerge(config.plot_def_opt, kwargs['options']) if 'formatting' not in kwargs: std_out('Using default formatting') formatting = config.ts_plot_def_fmt['mpl'] else: formatting = dict_fmerge(config.ts_plot_def_fmt['mpl'], kwargs['formatting']) # Style if formatting['style'] is not None: style.use(formatting['style']) else: style.use(config.plot_style) # Palette if formatting['palette'] is not None: set_palette(formatting['palette']) # Font size if formatting['fontsize'] is not None: rcParams.update({'font.size': formatting['fontsize']}) # Get dataframe df, subplots = prepare_data(self, traces, options) n_subplots = len(subplots) # Size sanity check if formatting['width'] > 50: std_out('Reducing width to 12') formatting['width'] = 12 if formatting['height'] > 50: std_out('Reducing height to 10') formatting['height'] = 10 # Plot figure, axes = plt.subplots(n_subplots, 1, sharex=formatting['sharex'], figsize=(formatting['width'], formatting['height'])) if n_subplots == 1: axes = array(axes) axes.shape = (1) for ax in axes: isbplt = where(axes == ax)[0][0] # Check if we are plotting any highlight for the trace if any(['-MEAN' in trace for trace in subplots[isbplt]]): has_hl = True elif any(['-MAX' in trace for trace in subplots[isbplt]]): has_hl = True elif any(['-MIN' in trace for trace in subplots[isbplt]]): has_hl = True else: has_hl = False for trace in subplots[isbplt]: if has_hl: if '-MEAN' in trace: alpha = formatting['alpha_highlight'] elif '-MAX' in trace: alpha = formatting['alpha_highlight'] elif '-MIN' in trace: alpha = formatting['alpha_highlight'] else: alpha = formatting['alpha_other'] else: alpha = 1 ax.plot(df.index, df[trace], label=trace, alpha=alpha) # TODO make this to compare to not None, so that we can send location if formatting['legend']: ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) if formatting['ylabel'] is not None: ax.set_ylabel(formatting['ylabel'][isbplt + 1]) if formatting['xlabel'] is not None: ax.set_xlabel(formatting['xlabel']) if formatting['yrange'] is not None: ax.set_ylim(formatting['yrange'][isbplt + 1]) if formatting['xrange'] is not None: if formatting['sharex']: ax.set_xlim(to_datetime(formatting['xrange'][1])) else: ax.set_xlim(to_datetime(formatting['xrange'][isbplt + 1])) if formatting['grid'] is not None: ax.grid(formatting['grid']) if formatting["decorators"] is not None: if 'axvline' in formatting['decorators']: for vline in formatting['decorators']['axvline']: ax.axvline(to_datetime(vline), linestyle='dotted', color='gray') if 'axhline' in formatting['decorators']: for vline in formatting['decorators']['axhline']: ax.axhline(vline, linestyle='dotted', color='gray') if 'xtext' in formatting['decorators']: for xtext in formatting['decorators']['xtext'].keys(): text = formatting['decorators']['xtext'][xtext] position = formatting['yrange'][isbplt + 1][1] - ( formatting['yrange'][isbplt + 1][1] - formatting['yrange'][isbplt + 1][0]) / 10 ax.text(to_datetime(xtext), position, text, size=15, color='gray') # TODO Fix if 'ytext' in formatting['decorators']: for ytext in formatting['decorators']['ytext'].keys(): text = formatting['decorators']['ytext'][ytext] position = formatting['xrange'][isbplt + 1][1] - ( formatting['xrange'][isbplt + 1][1] - formatting['yrange'][isbplt + 1][0]) / 10 ax.text(ytext, position, text, size=15, color='gray') figure.suptitle(formatting['title'], fontsize=formatting['title_fontsize']) plt.subplots_adjust(top=formatting['suptitle_factor']) if options['show']: plt.show() return figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar #import matplotlib.pyplot as plt import matplotlib.figure as mpl import matplotlib.dates as md import datetime as dt import os import csv from TURP1210.RP1210.RP1210Functions import * import logging logger = logging.getLogger(__name__) from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) #Depends on matplotlib from graphing markers = [ "D", "o", "v", "*", "^", "<", ">", "1", "2", "3", "4", "8", "s", "p", "P", "h", "H", "+", "x", "X", "d", "|" ] def get_plot_bytes(self, fig): """ A helper function to produce a bytestream from a matplotlib figure """ img = BytesIO() fig.figsize = (7.5, 8.5) #inches fig.savefig( img, format='PDF',
# encoding: utf-8 import numpy as np import matplotlib.pyplot as plt import sys from pylab import * from matplotlib import rcParams rcParams.update({'font.size': 18, 'weight': 'bold'}) patterns = ('/', '//', '-', '+', 'x', '\\', '\\\\', '*', 'o', 'O', '.') x = [] fluidw1 = [] fluidw2 = [] nsw1 = [] nsw2 = [] fluidratio = [] nsratio = [] ##now begin to read DCTCP fp = open("averag2.txt", "r") totaline = fp.readlines() for line in totaline: array = line.split() x.append(float(array[0])) fluidw1.append(float(array[1])) fluidw2.append(float(array[2])) nsw1.append(float(array[3])) nsw2.append(float(array[4])) fluidratio.append(float(array[1]) / float(array[2]))
def analysis(self, show=False): """perform a PDM analysis on each lightcurve""" from matplotlib import rcParams print 'Analysis' fig_width = 18.3 / 2.54 # width in inches, was 7.48in fig_height = 23.3 / 2.54 # height in inches, was 25.5 fig_size = [fig_width, fig_height] #set plot attributes params = { 'backend': 'Agg', 'axes.labelsize': 12, 'axes.titlesize': 12, 'font.size': 12, 'xtick.labelsize': 12, 'ytick.labelsize': 12, 'figure.figsize': fig_size, 'savefig.dpi': 300, 'font.family': 'sans-serif', 'axes.linewidth': 0.5, 'xtick.major.size': 2, 'ytick.major.size': 2, } rcParams.update(params) minperiod = 1.3 maxperiod = 15 for starid, vmag, bv in zip(self.stars, self.vmag, self.bv): print '%-24s ' % starid, try: lc = LightCurve(starid) except IOError: logger.error("Can't load lightcurve %s" % starid) print 'no lightcurve' self.setbad(starid) continue if len(lc) < 50: logger.warn("%s: not enough datapoints" % starid) print 'not enough datapoints' continue # perform a 3sigma clipping i = np.where(lc.hjd > 2456762)[0] lc.mag = lc.mag[i] lc.hjd = lc.hjd[i] lc.normalize() lc.clip() lc.detrend() lc.sigma_clip() lc.normalize() self.hjd = lc.hjd self.mag = lc.mag self.err = lc.err clean_periods, clean_amplitudes = lc.clean(minperiod, maxperiod) pdm_periods, pdm_thetas = lc.pdm(minperiod, maxperiod) #period = clean_periods[np.argmax(clean_amplitudes)] from scipy import interpolate i = np.argsort(clean_periods) c_periods = clean_periods[i] c_amps = clean_amplitudes[i] c_periods = np.insert(c_periods, 0, 0.0) c_amps = np.insert(c_amps, 0, 0.0) c_periods = np.insert(c_periods, -1, maxperiod) c_amps = np.insert(c_amps, -1, 0.0) c_int = interpolate.interp1d(c_periods, c_amps) # use interpolation function returned by `interp1d` sum_amp = c_int(pdm_periods) * (1. - pdm_thetas) sum_amp /= max(sum_amp) i = np.argmax(sum_amp) period = pdm_periods[i] theta = pdm_thetas[i] import functions as fx ci = np.argmax(c_amps) try: pgf_amp, pgf_mean, pgf_sigma = fx.gauss_fit( pdm_periods, 1. - pdm_thetas, pdm_thetas[i], period, 1.0) except: pgf_sigma = 0.0 try: cgf_amp, cgf_mean, cgf_sigma = fx.gauss_fit( c_periods, c_amps, c_amps[ci], c_periods[ci], 1.0) except: cfg_sigma = 0.0 sigma_limit = 5.3 theta_limit = 0.8 try: ci = np.argmax(c_amps) params = { 'period': period, 'period_err': pgf_sigma, 'clean_period': c_periods[ci], 'clean_amp': c_amps[ci], 'clean_sigma': cgf_sigma, 'theta': theta, 'freq': period, } keys = ', '.join(params.keys()) values = ', '.join([str(v) for v in params.values()]) query = """UPDATE ngc6633 SET (%s) = (%s) WHERE starid='%s';""" % ( keys, values, starid) self.wifsip.execute(query) except: print 'Cannot store params for starid %s' % starid mamp = np.mean(clean_amplitudes) if max(clean_amplitudes ) > sigma_limit * mamp and pdm_thetas[i] < theta_limit: print "%.2f %.1f" % (period, max(clean_amplitudes) / mamp) self.setperiod(starid, period) else: print '< %.1f sigmas or theta %.2f > %.2f' % ( sigma_limit, pdm_thetas[i], theta_limit) self.setperiod(starid, np.nan) continue amp, _ = lc.phased(period) self.setamp(starid, amp) star = {'tab': 0, 'bv': bv} plt.subplot( 411) ################################################## plt.title('%s (%d) V = %.2f B-V=%.2f' % (starid, star['tab'], vmag, bv)) self.plot_lightcurve() plt.subplot( 412) ################################################## self.plot_clean(clean_periods, clean_amplitudes) plt.subplot( 413) ################################################## plt.plot(pdm_periods, sum_amp, 'g') plt.axvline(period, color='b') self.plot_pdm(pdm_periods, pdm_thetas) plt.subplot( 414) ################################################## self.plot_phase(period) # plt.scatter(tp, yp-np.mean(yp), edgecolor='none', alpha=0.75) # plt.plot(tp1,c[1]*s1+c[2]*c1+c[3]*s2+c[4]*c2, 'k', # linestyle='--', linewidth=2) # plt.xlim(0.0,period) # plt.ylim(max(yp-np.mean(yp)),min(yp-np.mean(yp))) # plt.xlabel('P = %.4f' % period) # plt.grid() # #plt.show() # period_err = 0.0 # comment = 'P=%6.3f+-%.3f a=%.3f+-%.4f %.2f' % \ # (period, period_err, amp, amp_err, theta) # plt.savefig(config.plotpath+'%s(%d).pdf' % (starid,star['tab'])) # plt.close() # # logger.info( comment) # print comment if show: plt.show() else: plt.savefig(config.plotpath + '%s(%d).pdf' % (starid, star['tab'])) plt.close()
def make_boxplot(caObj, name): low_clouds = get_calipso_low_clouds(caObj) high_clouds = get_calipso_high_clouds(caObj) medium_clouds = get_calipso_medium_clouds(caObj) height_c = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,0] - caObj.calipso.all_arrays['elevation']) height_c1 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,0] - caObj.calipso.all_arrays['elevation']) height_c2 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,1] - caObj.calipso.all_arrays['elevation']) height_c3 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,2] - caObj.calipso.all_arrays['elevation']) height_c4 = (1000*caObj.calipso.all_arrays['layer_top_altitude'][:,3] - caObj.calipso.all_arrays['elevation']) height_pps = caObj.avhrr.all_arrays['ctth_height'] bias_1 = height_pps - height_c1 bias_2 = height_pps - height_c2 bias_3 = height_pps - height_c3 bias_4 = height_pps - height_c4 thin = np.logical_and(caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']<0.30, caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']>0) very_thin = np.logical_and(caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']<0.10, caObj.calipso.all_arrays['feature_optical_depth_532_top_layer_5km']>0) thin_top = np.logical_and(caObj.calipso.all_arrays['number_layers_found']>1, thin) thin_1_lay = np.logical_and(caObj.calipso.all_arrays['number_layers_found']==1, thin) #height_c[thin_top] = height_c2[thin_top] #height_c[np.abs(bias_1)<np.abs(bias_2)] = height_c1[np.abs(bias_1)<np.abs(bias_2)] #height_c[np.abs(bias_2)<np.abs(bias_1)] = height_c2[np.abs(bias_2)<np.abs(bias_1)] #bias = height_pps - height_c #height_c[np.abs(bias_3)<np.abs(bias)] = height_c3[np.abs(bias_3)<np.abs(bias)] #height_c[~thin_top] = height_c1[~thin_top] #height_c[thin_top] = height_c2[thin_top] use = np.logical_and(height_pps >-1, caObj.calipso.all_arrays['layer_top_altitude'][:,0]>=0) use = np.logical_and(height_pps <45000,use) low = np.logical_and(low_clouds,use) medium = np.logical_and(medium_clouds,use) high = np.logical_and(high_clouds,use) c_all = np.logical_or(high,np.logical_or(low,medium)) high_very_thin = np.logical_and(high, very_thin) high_thin = np.logical_and(high, np.logical_and(~very_thin,thin)) high_thick = np.logical_and(high, ~thin) #print "thin, thick high", np.sum(high_thin), np.sum(high_thick) bias = height_pps - height_c limit = np.percentile(bias[use],5) #print limit abias = np.abs(bias) MAE = np.mean(abias[c_all]) #abias[abias>2000]=2000 print name.ljust(30, " "), "%3.1f"%(np.mean(abias[c_all])), "%3.1f"%(np.mean(abias[low])),"%3.1f"%(np.mean(abias[medium])),"%3.1f"%(np.mean(abias[high])), "%3.1f"%(limit) c_all = np.logical_or(np.logical_and(~very_thin,high),np.logical_or(low,medium)) number_of = np.sum(c_all) #print name.ljust(30, " "), "%3.1f"%(np.sum(abias[c_all]<250)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<1500)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<2000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<3000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<4000)*100.0/number_of), "%3.1f"%(np.sum(abias[c_all]<5000)*100.0/number_of) from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) fig = plt.figure(figsize = (6,9)) ax = fig.add_subplot(111) plt.xticks(rotation=70) #plt.tight_layout() #plt.subplots_adjust(left=0.2) #plt.subplots_adjust(left=10, bottom=10, right=10, top=10, wspace=0, hspace=0) ax.fill_between(np.arange(0,8),-500,500, facecolor='green', alpha=0.6) ax.fill_between(np.arange(0,8),-1000,1000, facecolor='green', alpha=0.4) ax.fill_between(np.arange(0,8),-1500,1500, facecolor='green', alpha=0.2) ax.fill_between(np.arange(0,8),2000,15000, facecolor='red', alpha=0.2) ax.fill_between(np.arange(0,8),-2000,-15000, facecolor='red', alpha=0.2) for y_val in [-5,-4,-3,-2,2,3,4,5]: plt.plot(np.arange(0,8), y_val*1000 + 0*np.arange(0,8),':k') plt.plot(np.arange(0,8), -10*1000 + 0*np.arange(0,8),':k') plt.plot(np.arange(0,8), 0 + 0*np.arange(0,8),'k') plt.boxplot([bias[low],bias[medium],bias[high],bias[high_thick],bias[high_thin],bias[high_very_thin]],whis=[5, 95],sym='', labels=["low","medium","high-all","high-thick\n od>0.4","high-thin \n 0.1<od<0.4","high-vthin\n od<0.1"],showmeans=True) ax.set_ylim(-14000,8000) plt.title("%s MAE = %3.0f"%(name,MAE)) plt.savefig("/home/a001865/PICTURES_FROM_PYTHON/CTTH_LAPSE_RATE_INVESTIGATION/ctth_box_plot_%s_5_95_filt.png"%(name))
center_fudge = np.array([15, 30]) # compensate for font bounding box padding tagline_scale_fudge = 0.97 # to get justification right tagline_offset_fudge = np.array([0, -100.]) # font, etc rcp = { 'font.sans-serif': ['Primetime'], 'font.style': 'normal', 'font.weight': 'black', 'font.variant': 'normal', 'figure.dpi': dpi, 'savefig.dpi': dpi, 'contour.negative_linestyle': 'solid' } plt.rcdefaults() rcParams.update(rcp) # initialize figure (no axes, margins, etc) fig = plt.figure(1, figsize=(5, 2.25), frameon=False, dpi=dpi) ax = plt.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() fig.add_axes(ax) # fake field data delta = 0.01 x = np.arange(-8.0, 8.0, delta) y = np.arange(-3.0, 3.0, delta) X, Y = np.meshgrid(x, y) xy = np.array([X, Y]).transpose(1, 2, 0) Z1 = multivariate_normal.pdf(xy, mean=[-5.0, 0.9],
def MultiLinePlot(xaxis, yvals, line_labels, xlabel, ylabel, colors=None, styles=None, xmax=-1, ymax=-1, ymin=None, xmin=None, ylog=True, xdates=False, vertlines=None, vlinelabel=None, xlog=False, title=None, width_factor=0.9, legend_xoff=0.4, legend_yoff=0.75): if colors is None: colors = [] if styles is None: styles = [] if(xdates): xaxis = mdate.epoch2num(xaxis) if(vertlines): vertlines = mdate.epoch2num(vertlines) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.set_xlabel(xlabel) ax1.set_ylabel(ylabel) if(ymin is None): if(ylog): ymin = min([min(y) for y in yvals])*0.5 if(ymin <= 0): print("error: ymin is ", ymin, " on a log-y axis. Defaulting to 1e-5") ymin = 1e-5 else: ymin = min([min(y) for y in yvals])*0.95 if(xmin is None): xmin = min(xaxis) if(xlog): ax1.set_xscale('log') else: ax1.set_xscale('linear') if(ylog): ax1.set_yscale('log') else: ax1.set_yscale('linear') if(ymax == -1): if(ylog): ax1.set_ylim(ymin,max([max(y) for y in yvals])*1.5) else: ax1.set_ylim(ymin,max([max(y) for y in yvals])*1.05) else: ax1.set_ylim(ymin,ymax) if(xmax == -1): ax1.set_xlim(xmin,max(xaxis)) else: ax1.set_xlim(xmin,xmax) #for i, y in enumerate(yvals): if not colors: colors = tab_colors if not styles: styles = category_styles for i in range(len(yvals)): ax1.plot(xaxis,yvals[i],color=colors[i%10],linestyle=styles[i%len(styles)]) if(vertlines is not None): for v in vertlines: ax1.axvline(v,color='k',linestyle='-')#,label=vlinelabel) if(xdates): #date_fmt = '%y-%m-%d %H:%M:%S' date_fmt = '%y-%m-%d' date_formatter = mdate.DateFormatter(date_fmt,tz=timezone('US/Eastern')) ax1.xaxis.set_major_formatter(date_formatter) fig.autofmt_xdate() else: pass #start,end = ax1.get_xlim() #diff = (end - start) / 8. #ax1.xaxis.set_ticks(np.arange(start,end,diff)) #ax1.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f')) #plt.setp(ax1.get_xticklabels(), rotation=30,\ #horizontalalignment='right') box = ax1.get_position() if(len(yvals) == 1): if(not title): ax1.set_title(line_labels[0]) else: ax1.set_title(title) else: if(title): ax1.set_title(title) ax1.set_position([box.x0,box.y0,box.width*width_factor,box.height]) ax1.legend(line_labels,loc='center left',\ bbox_to_anchor=(legend_xoff,legend_yoff),ncol=1) rcParams.update({'font.size':14}) #plt.gcf().subplots_adjust(left=0.16) #plt.gcf().subplots_adjust(bottom=0.22) #plt.gcf().subplots_adjust(right=0.05) #plt.savefig(outname) #plt.close() return fig
from io import StringIO try: rich_output = True import jinja2 from matplotlib import rcParams as mpl_params from matplotlib import pyplot as plt from matplotlib.axes import Axes from ms_peak_picker.utils import draw_peaklist, draw_raw mpl_params.update({ 'figure.facecolor': 'white', 'figure.edgecolor': 'white', 'figure.figsize': (5, 3.5), 'font.size': 10, # 72 dpi matches SVG # this only affects PNG export, as SVG has no dpi setting 'savefig.dpi': 72, # 10pt still needs a little more room on the xlabel: 'figure.subplot.bottom': .125 }) def png_plot(figure, **kwargs): buffer = render_plot(figure, format='png', **kwargs) return "<img src='data:image/png;base64,%s'>" % urllib.quote( buffer.getvalue().encode("base64")) def svg_plot(figure, **kwargs): buffer = render_plot(figure, format='svg', **kwargs) return buffer.getvalue()
interval=20, repeat_delay=700) anim.save('anim3dplot.gif', writer='imagemagick', fps=15) if draw: pl.show() else: pl.close() def usage(): print('Usage: visualise_hpbresults.py --input hpbbleu_file [--show-plots]') exit(1) if __name__ == '__main__': opts, args = getopt.getopt(sys.argv[1:], None, ['show-plots', 'input=']) if len(args) > 0 or not 1 <= len(opts) <= 2: print('Invalid arguments or fewer parameters.') usage() draw = False for o, a in opts: if o == '--show-plots': draw = True elif o == '--input': ip = a else: print('Invalid parameters.') usage() p, b, r = 'Population Limit', 'BLEU', 'Runtime (minutes)' data = loadtxt(ip, dtype=[(p, 'int'), (b, 'float'), (r, 'float')]) rcParams.update({'font.size': 14}) graph(p, b, r) #graph(p,r,b) #graph3D()
import settings import const import pandas as pd from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) # to prevent labels going out of plot! import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt # Access default configurations config = settings.config[const.DEFAULT] # Read cleaned data df = pd.read_csv(config[const.BJ_OBSERVED], delimiter=';', low_memory=False) corr = df.corr() fig, ax = plt.subplots() cax = ax.matshow(corr, vmin=-1, vmax=1, cmap='hot') plt.xticks(range(len(corr.columns)), corr.columns, rotation=90) plt.yticks(range(len(corr.columns)), corr.columns) fig.colorbar(cax) # correspondence of colors to values # fig = plt.figure() # ax1 = fig.add_subplot(111) # cmap = cm.get_cmap('jet', 30) # cax = ax1.imshow(corr, interpolation="nearest", cmap=cmap) # ax1.grid(True) # plt.title('Feature Correlation') # ax1.set_xticklabels(corr.columns,fontsize=10) # ax1.set_yticklabels(corr.columns,fontsize=10)
def initialize_plotting_parameters(): rcParams.update(mtparams)