def diffusion1D(length_microns, log10D_m2s, time_seconds, init=1., fin=0., erf_or_sum='erf', show_plot=True, style=styles.style_blue, infinity=100, points=100, centered=True, axes=None, symmetric=True, maximum_value=1.): """ Simplest implementation for 1D diffusion. Takes required inputs length, diffusivity, and time and plots diffusion curve on new or specified figure. Optional inputs are unit initial value and final values. Defaults assume diffusion out, so init=1. and fin=0. Reverse these for diffusion in. Change scale of y-values with maximum_value keyword. Returns figure, axis, x vector in microns, and model y data. """ if symmetric is True: params = params_setup1D(length_microns, log10D_m2s, time_seconds, init=init, fin=fin) x_diffusion, y_diffusion = diffusion1D_params(params, points=points) if centered is False: a_length = (max(x_diffusion) - min(x_diffusion)) / 2 x_diffusion = x_diffusion + a_length else: # multiply length by two params = params_setup1D(length_microns*2, log10D_m2s, time_seconds, init=init, fin=fin) x_diffusion, y_diffusion = diffusion1D_params(params, points=points) # divide elongated profile in half x_diffusion = x_diffusion[int(points/2):] y_diffusion = y_diffusion[int(points/2):] if centered is True: a_length = (max(x_diffusion) - min(x_diffusion)) / 2 x_diffusion = x_diffusion - a_length if show_plot is True: if axes is None: fig = plt.figure() ax = SubplotHost(fig, 1,1,1) ax.grid() ax.set_ylim(0, maximum_value) ax.set_xlabel('position ($\mu$m)') ax.set_xlim(min(x_diffusion), max(x_diffusion)) ax.plot(x_diffusion, y_diffusion*maximum_value, **style) ax.set_ylabel('Unit concentration or final/initial') fig.add_subplot(ax) else: axes.plot(x_diffusion, y_diffusion*maximum_value, **style) fig = None ax = None else: fig = None ax = None return fig, ax, x_diffusion, y_diffusion
def _plot(p1_infiles,p2_infiles2,bottom_label,left_label,tau_b=1000): fig = plt.figure(figsize=(12,9)) ax_host = SubplotHost(fig, 1,1,1) fig.add_subplot(ax_host) for p1_file, p2_file in zip(p1_infiles,p2_infiles): p1, p2 = get_ave_ste(p1_file, p2_file, tau_b=1000) ax_host.errorbar(p1[0],p2[0], xerr=p1[1], yerr=p2[1],label=p1_file[:4]) ax_host.text(p1[0]*1.02,p2[0]*1.02,p1_file[:7]) ax_host.axis["bottom"].set_label(bottom_label) ax_host.axis["left"].set_label(left_label) ax_host.grid() # if wanna legend, uncomment the following line # plt.legend() plt.show()
def Arrhenius_outline(xlow=6., xhigh=11., ybottom=-18., ytop=-8., celsius_labels = np.arange(0, 2000, 100), shrink_axes_to_fit_legend_by = 0.3, make_legend=False, lower_legend_by=-2., ncol=2): """ Make Arrhenius diagram outline. Returns figure, axis, legend handle. low, high, top, and bottom set the x and y axis limits. celsius_labels sets where to make the temperature tick marks. If you have issues with the legend position or overlap with main diagram, play with the numbers for shrink_legend_by and lower_legend_by ncol sets the number of columns in the legend. """ fig = plt.figure() ax = SubplotHost(fig, 1,1,1) ax_celsius = ax.twin() parasite_tick_locations = 1e4/(celsius_labels + 273.15) ax_celsius.set_xticks(parasite_tick_locations) ax_celsius.set_xticklabels(celsius_labels) fig.add_subplot(ax) ax.axis["bottom"].set_label("10$^4$/Temperature (K$^{-1}$)") ax.axis["left"].set_label("log$_{10}$diffusivity (m$^{2}$/s)") ax_celsius.axis["top"].set_label("Temperature ($\degree$C)") ax_celsius.axis["top"].label.set_visible(True) ax_celsius.axis["right"].major_ticklabels.set_visible(False) ax.set_xlim(xlow, xhigh) ax.set_ylim(ybottom, ytop) ax.grid() # main legend below if make_legend is True: legend_handles_main = [] box = ax.get_position() ax.set_position([box.x0, box.y0 + box.height*shrink_axes_to_fit_legend_by, box.width, box.height*(1.0-shrink_axes_to_fit_legend_by)]) main_legend = plt.legend(handles=legend_handles_main, numpoints=1, ncol=ncol, bbox_to_anchor=(xlow, ybottom, xhigh-xlow, lower_legend_by), bbox_transform=ax.transData, mode='expand') plt.gca().add_artist(main_legend) else: legend_handles_main = None return fig, ax, legend_handles_main
def plot_diffusion1D(x_microns, model, initial_value=None, fighandle=None, axishandle=None, top=1.2, style=None, fitting=False, show_km_scale=False, show_initial=True): """Takes x and y diffusion data and plots 1D diffusion profile input""" a_microns = (max(x_microns) - min(x_microns)) / 2. a_meters = a_microns / 1e3 if fighandle is None and axishandle is not None: print 'Remember to pass in handles for both figure and axis' if fighandle is None or axishandle is None: fig = plt.figure() ax = SubplotHost(fig, 1, 1, 1) ax.grid() ax.set_ylim(0, top) else: fig = fighandle ax = axishandle if style is None: if fitting is True: style = {'linestyle': 'none', 'marker': 'o'} else: style = styles.style_lightgreen if show_km_scale is True: ax.set_xlabel('Distance (km)') ax.set_xlim(0., 2. * a_meters / 1e3) x_km = x_microns / 1e6 ax.plot((x_km) + a_meters / 1e3, model, **style) else: ax.set_xlabel('position ($\mu$m)') ax.set_xlim(-a_microns, a_microns) ax.plot(x_microns, model, **style) if initial_value is not None and show_initial is True: ax.plot(ax.get_xlim(), [initial_value, initial_value], '--k') ax.set_ylabel('Unit concentration or final/initial') fig.add_subplot(ax) return fig, ax
def Arrhenius_outline(low=6., high=11., bottom=-18., top=-8., celsius_labels=np.arange(0, 2000, 100), figsize_inches=(6, 4), shrinker_for_legend=0.3, generic_legend=True, sunk=-2., ncol=2): """Make Arrhenius diagram outline. Returns figure, axis, legend handle""" fig = plt.figure(figsize=figsize_inches) ax = SubplotHost(fig, 1, 1, 1) ax_celsius = ax.twin() parasite_tick_locations = 1e4 / (celsius_labels + 273.15) ax_celsius.set_xticks(parasite_tick_locations) ax_celsius.set_xticklabels(celsius_labels) fig.add_subplot(ax) ax.axis["bottom"].set_label("10$^4$/Temperature (K$^{-1}$)") ax.axis["left"].set_label("log$_{10}$diffusivity (m$^{2}$/s)") ax_celsius.axis["top"].set_label("Temperature ($\degree$C)") ax_celsius.axis["top"].label.set_visible(True) ax_celsius.axis["right"].major_ticklabels.set_visible(False) ax.set_xlim(low, high) ax.set_ylim(bottom, top) ax.grid() # main legend below legend_handles_main = [] box = ax.get_position() ax.set_position([ box.x0, box.y0 + box.height * shrinker_for_legend, box.width, box.height * (1.0 - shrinker_for_legend) ]) main_legend = plt.legend(handles=legend_handles_main, numpoints=1, ncol=ncol, bbox_to_anchor=(low, bottom, high - low, sunk), bbox_transform=ax.transData, mode='expand') plt.gca().add_artist(main_legend) return fig, ax, legend_handles_main
def plot_area_profile_outline(centered=True, peakwn=None, set_size=(6.5, 4), ytop=1.2, wholeblock=False, heights_instead=False, show_water_ppm=True): """ Set up area profile outline and style defaults. Default is for 0 to be the middle of the profile (centered=True). """ fig = plt.figure(figsize=set_size) ax = SubplotHost(fig, 1,1,1) fig.add_subplot(ax) ax_ppm = ax.twinx() ax_ppm.axis["top"].major_ticklabels.set_visible(False) if show_water_ppm is True: pass else: ax_ppm.axis["right"].major_ticklabels.set_visible(False) ax.set_xlabel('Position ($\mu$m)') # Set y-label if wholeblock is True: if heights_instead is False: ax.set_ylabel('Area/Area$_0$') else: ax.set_ylabel('Height/Height$_0$') else: if heights_instead is False: ax.set_ylabel('Area (cm$^{-2}$)') else: ax.set_ylabel('Height (cm$^{-1}$)') ax.set_ylim(0, ytop) ax.grid() return fig, ax, ax_ppm
def make_3DWB_water_profile(final_profile, water_ppmH2O_initial=None, initial_profile=None, initial_area_list=None, initial_area_positions_microns=None, show_plot=True, top=1.2, fig_ax=None): """Take a profile and initial water content. Returns the whole-block water concentration profile based on the profile's attribute wb_areas. If wb_areas have not been made, some initial profile information and various options are passed to make_3DWB_area_profile(). Default makes a plot showing A/Ao and water on parasite y-axis """ fin = final_profile init = initial_profile # Set initial water if water_ppmH2O_initial is not None: w0 = water_ppmH2O_initial else: if fin.sample is not None: if fin.sample.initial_water is not None: w0 = fin.sample.initial_water elif init is not None: if init.sample is not None: if init.sample.initial_water is not None: w0 = init.sample.initial_water else: print 'Need initial water content.' return False # Set whole-block areas if (fin.wb_areas is not None) and (len(fin.wb_areas) > 0): wb_areas = fin.wb_areas else: wb_areas = make_3DWB_area_profile(fin, initial_profile, initial_area_list, initial_area_positions_microns) water = wb_areas * w0 if show_plot is True: # Use a parasite y-axis to show water content fig = plt.figure() ax_areas = SubplotHost(fig, 1, 1, 1) fig.add_subplot(ax_areas) area_tick_marks = np.arange(0, 100, 0.2) ax_areas.set_yticks(area_tick_marks) ax_water = ax_areas.twin() ax_water.set_yticks(area_tick_marks) if isinstance(w0, uncertainties.Variable): ax_water.set_yticklabels(area_tick_marks * w0.n) else: ax_water.set_yticklabels(area_tick_marks * w0) ax_areas.axis["bottom"].set_label('Position ($\mu$m)') ax_areas.axis["left"].set_label('Final area / Initial area') ax_water.axis["right"].set_label('ppm H$_2$O') ax_water.axis["top"].major_ticklabels.set_visible(False) ax_water.axis["right"].major_ticklabels.set_visible(True) ax_areas.grid() ax_areas.set_ylim(0, 1.2) if fin.len_microns is not None: leng = fin.len_microns else: leng = fin.set_len() ax_areas.set_xlim(-leng / 2.0, leng / 2.0) style = fin.choose_marker_style() ax_areas.plot([-leng / 2.0, leng / 2.0], [1, 1], **style_1) ax_areas.plot(fin.positions_microns - leng / 2.0, wb_areas, **style) return water, fig, ax_areas else: return water
else: fig1 = plot.figure() fig2 = fig1 figs = [fig1] figs_N = 2 fig1_y = 1 fig2_y = 2 plt.subplots_adjust(hspace=0.0) axprops = dict() if plot_V: ax_V_Eh = SubplotHost(fig1, figs_N, 1, fig1_y, **axprops) ax_V_Eh_to_Volt = mtransforms.Affine2D().scale(1.0, cst.eV_to_Eh) ax_V_Volt = ax_V_Eh.twin(ax_V_Eh_to_Volt) ax_V_Volt.set_viewlim_mode("transform") ax_V_Eh.grid(True) ax_V_Volt.set_ylabel("Potential (Volt)") ax_V_Eh.set_ylabel("Potential energy of a 1+ (Hartree)") axprops["sharex"] = ax_V_Volt plt.setp(ax_V_Volt.get_xticklabels(), visible=False) # ax_V_Eh.set_title(r"Potential") if plot_U: ax_U_Eh = SubplotHost(fig2, figs_N, 1, fig2_y, **axprops) ax_U_Eh_to_eV = mtransforms.Affine2D().scale(1.0, cst.eV_to_Eh) ax_U_eV = ax_U_Eh.twin(ax_U_Eh_to_eV) ax_U_eV.set_viewlim_mode("transform")