for nr, (rect, txt) in enumerate(zip(holeRects, yTicks)): width = rect.get_width() height = rect.get_y() # Add 4% padding x = 0 y = height ax.text(x, y, txt, ha="center", va="center") ax.set_xlabel(r"$[\mathrm{s}^{-1}]$") ax.spines["top"] .set_visible(False) ax.spines["left"] .set_visible(False) ax.spines["right"].set_visible(False) ax.get_yaxis().set_visible(False) PlotHelper.makePlotPretty(ax, legend=False, rotation=45) ax.grid(False) # Make legend manually handles = (holeRects[0], blobRects[0]) labels = ("$\mathrm{Holes}$",\ "$\mathrm{Blobs}$",\ ) fig.suptitle(r"$\mathrm{Average\;blobs\;and\;holes\;per\;second}$", y=1.1) fig.legend(handles ,\ labels ,\ bbox_to_anchor=(1.02, 1.0) ,\ loc="upper left" ,\ borderaxespad=0. ,\ bbox_transform = ax.transAxes,\
ddtTxt = r"$\partial_t \Omega^D$" nnAx.text(0.4, 0, ddtTxt, color="k",\ va="center", ha="center", size=size,\ bbox={"facecolor":"white",\ "edgecolor":"none" ,\ "boxstyle" :"round",\ "alpha" :0.9},\ ) nnAx.set_xlabel(r"$z\;[\mathrm{m}]$") nnAx.set_ylabel(r"$[\mathrm{m}^{-3}\mathrm{s}^{-2}]$") nnAx.set_title(r"$d=1\%$") PlotHelper.makePlotPretty(nnAx, legend=False, rotation=45) #}}} #{{{Extract and plot no neutral nn = 0 path = "../../CSDXMagFieldScanAr/visualizationNormalized/B0_0.06/field1D/vortD-parallel-1D-0.pickle" with open(path, "rb") as f: normalFig = pickle.load(f) axes = normalFig.get_axes() for ax in axes[:-1]: normalFig.delaxes(ax) noNeutralAx = axes[-1]
"edgecolor":"none" ,\ "boxstyle" :"round",\ "alpha" :0.9},\ ) ddtTxt = r"$\partial_t j_\parallel$" newAx.text(1.4, 0, ddtTxt, color="k",\ va="center", ha="center", size="x-large",\ bbox={"facecolor":"white",\ "edgecolor":"none" ,\ "boxstyle" :"round",\ "alpha" :0.9},\ ) newAx.set_xlabel(r"$z\;[\mathrm{m}]$") newAx.set_ylabel(r"$[\mathrm{C}\mathrm{m}^{-2}\mathrm{s}^{-2}]$") # Create new title theSplit = suptitle.split("=") rho = float(theSplit[1].split("$")[2]) * rhoS t = eval(theSplit[-1].split("$")[2].\ replace("{","").replace("}","").replace("\\cdot 10^","e"))/omCI newAx.set_title((r"$\rho={}\;\mathrm{{m}}\quad" r"\theta=0^{{\circ}}\quad t={}\;\mathrm{{s}}$").\ format(plotNumberFormatter(rho,0).replace("$",""),\ plotNumberFormatter(t,0) .replace("$","")\ )) PlotHelper.makePlotPretty(newAx, legend=False) PlotHelper.savePlot(fig, "jParBalanceNy{}.pdf".format(ny))
data["Arithmetics"]["x"] = xBarVals[0::lenKeys] data["Communication"]["x"] = xBarVals[1::lenKeys] data["Input/output"]["x"] = xBarVals[2::lenKeys] data["Laplace inversions"]["x"] = xBarVals[3::lenKeys] data["Time solver"]["x"] = xBarVals[4::lenKeys] tickVals = data["Input/output"]["x"] # Create the figure fig, ax = plt.subplots(figsize=SizeMaker.standard(a=0.5, s=0.5)) for key in keys: d = data[key] ax.bar(d["x"], d["mean"], yerr=d["std"], label=key) PlotHelper.makePlotPretty(ax) ax.xaxis.grid(False) ax.xaxis.set_ticks(tickVals) ax.xaxis.set_ticklabels( ("Initial\nphase", "Expand\nphase", "Linear\nphase", "Turbulent\nphase")) ax.set_ylabel("$\%$") # Move legend outside handles, labels = ax.get_legend_handles_labels() # Remove old legend leg = ax.legend() leg.remove() fig.legend(handles,\ labels ,\ bbox_to_anchor=(1.05, 1.0),\
width = rect.get_width() height = rect.get_y() # Add 4% padding x = width*1.04 + lowestVal y = height + rect.get_height()/2 perpAx.text(x, y, txt, ha="left", va="center") perpAx.set_xlabel(r"$[\mathrm{s}^{-1}]$") perpAx.set_title(r"$\mathrm{Perpendicular}$") perpAx.spines["top"] .set_visible(False) perpAx.spines["left"] .set_visible(False) perpAx.spines["right"].set_visible(False) perpAx.get_yaxis().set_visible(False) PlotHelper.makePlotPretty(perpAx, xbins=5, legend=False, rotation=45) perpAx.grid(False) # Par values xBarVals = tuple(range(len(perpPerTime)*2)) ionXBarVals = xBarVals[1::2] elXBarVals = xBarVals[0::2] # Find the lowest value lowestVal = np.min(perpPerTime) # Pad with 5% lowestVal = 0.95*lowestVal # Plot elRects = parAx.barh(elXBarVals ,\
def checkModes(path): path = path[0] defaultCollect = partial(collect,\ path=path, xguards=False, yguards=False, info=False) unfiltered = defaultCollect("unfiltered") filtered = defaultCollect("filtered") Lx = defaultCollect("Lx") dx = defaultCollect("dx") maxRhoInd = unfiltered.shape[0] # NOTE: maxRhoInd counts from 0 indices = (0, int(maxRhoInd / 2) - 1, maxRhoInd - 1) filteredDict = {} unfilteredDict = {} fftFiltered = {} fftUnfiltered = {} # Print stats kMax = np.floor((filtered.shape[-1] / 2) * (2 / 3)) print(("\n\nMax allowed mode number on outer circumference = Nyquist mode " "* Orszag = floor((nz/2)*(2/3)) = floor(({}/2)*(2/3)) = {} ")\ .format(filtered.shape[-1], kMax) ) lambdaMin = 2 * np.pi * (Lx - dx[0, 0] / 2) / kMax print(("\nThis means that the minimum wavelength" " lambdaMin = outer circmference/kMax =" " 2*pi*(rho-dx/2)/kMax = 2*pi*({}-{}/2)/{} = {}")\ .format(Lx, dx[0,0], kMax, lambdaMin) ) print("\nThis means that kCurX = floor(cur circumference/lambdaMin)") for ind in range(filtered.shape[0]): # The first inner point is 0.5*dx from the origin x = dx[0, 0] * (ind + 0.5) curCirc = 2 * np.pi * x kCurXClean = curCirc / lambdaMin kCurX = np.floor(curCirc / lambdaMin) # Find first index where the value is close to 0 firstZero\ = np.where(\ np.isclose(\ np.fft.fft(\ filtered[ind, 0, :].flatten().real), 0.0))[0][0] print(("Ind={:<3} => x={:<7.2f}=> cur circumference={:<7.2f}" " => kCurX={:<2d}, floored from {:<9.6f}. Last value found" " on mode {}")\ .format(ind, x, curCirc, int(kCurX), kCurXClean, firstZero-1) ) for ind in indices: unfilteredDict[ind] = unfiltered[ind, 0, :].flatten() filteredDict[ind] = filtered[ind, 0, :].flatten() fftUnfiltered[ind] = np.fft.fft(unfilteredDict[ind]) fftFiltered[ind] = np.fft.fft(filteredDict[ind]) fig = plt.figure() axUnfilter = fig.add_subplot(221) axFilter = fig.add_subplot(223) axFFTUnfilter = fig.add_subplot(222) axFFTFilter = fig.add_subplot(224) axUnfilter.set_xlabel("Unfiltered") axFilter.set_xlabel("Filtered") axFFTUnfilter.set_xlabel("FFT Unfiltered") axFFTFilter.set_xlabel("FFT Filtered") for ind in indices: axUnfilter.plot(unfilteredDict[ind].real, "o", alpha=0.5, label="Index {}".format(ind)) axFilter.plot(filteredDict[ind].real, "o", alpha=0.5, label="Index {}".format(ind)) axFFTUnfilter.plot(fftUnfiltered[ind].real, "o", alpha=0.5, label="Index {}".format(ind)) axFFTFilter.plot(fftFiltered[ind].real, "o", alpha=0.5, label="Index {}".format(ind)) PlotHelper.makePlotPretty(axUnfilter) PlotHelper.makePlotPretty(axFilter) PlotHelper.makePlotPretty(axFFTUnfilter) PlotHelper.makePlotPretty(axFFTFilter) plt.show()
yDown = np.array(yDown) - np.array(y) yUp = np.array(y) - np.array(yUp) yerr = (np.array(yDown), np.array(yUp)) # Replot newAx.errorbar(x ,\ y ,\ color = color ,\ yerr = yerr ,\ **errorbarOptions) newAx.set_ylabel(ax.get_ylabel()) newAxes[0].set_title(fig.texts[0].get_text()) newAxes[1].set_xlabel(reAx.get_xlabel()) PlotHelper.makePlotPretty(newAxes[0], legend=False, rotation=45) PlotHelper.makePlotPretty(newAxes[1], legend=False, rotation=45) # Manually set the x and the y as the figure has different coordinates x = 0.4 y = -0.4 newFig.legend(handles,\ newLabels,\ bbox_to_anchor=(x, y),\ ncol=2,\ loc="upper center",\ borderaxespad=0.,\ bbox_transform = newAxes[1].transAxes,\ )
xAxis = ax.get_lines()[0].get_data()[0] # Set legend to ylabel handles, labels = ax.get_legend_handles_labels() yLabel = labels[0] xLabel = fig.get_axes()[3].get_xlabel() plt.close(fig) # Make a new figure fig, ax = plt.subplots(figsize=SizeMaker.standard(s=0.5)) for scan in scans: curScan = float(scan[4:]) ax.plot(xAxis, sD[scan]["line"],\ ls = sD[scan]["ls"],\ color = sD[scan]["color"],\ marker = sD[scan]["marker"],\ ms = 7,\ alpha = 0.7,\ label = "$B_0 = {} \mathrm{{T}}$".format(curScan)\ ) ax.set_ylabel(yLabel) ax.set_xlabel(xLabel) PlotHelper.makePlotPretty(ax, rotation=45) fileName = "BScanPosOfFluct.pdf" PlotHelper.savePlot(fig, fileName)
marker = sD[scan]["marker"],\ ms = 7,\ alpha = 0.7,\ label = "$B_0 = {} \mathrm{{T}}$".format(curScan)\ ) sAx.set_ylabel(key.replace("Skewness", r"Skewness \;")) elif "kurt" in key.lower(): kAx.plot(xAxis, sD[scan][key],\ ls = sD[scan]["ls"],\ color = sD[scan]["color"],\ marker = sD[scan]["marker"],\ alpha = 0.7,\ ms = 7,\ ) kAx.set_ylabel(key.replace("quadkurtosis", r"; kurtosis \;")) kAx.set_xlabel(r"$\rho$ $[m]$") PlotHelper.makePlotPretty(sAx, rotation=45) PlotHelper.makePlotPretty(kAx, rotation=45, legend=None) sAx.legend(bbox_to_anchor=(1.4, 0.5),\ loc="center",\ borderaxespad=0.,\ bbox_transform = sAx.transAxes,\ ) fig.tight_layout() fileName = "BScanSkewKurt.pdf" PlotHelper.savePlot(fig, fileName)