本文整理汇总了Python中GeneralUtil.python.PlotUtilities.variable_string方法的典型用法代码示例。如果您正苦于以下问题:Python PlotUtilities.variable_string方法的具体用法?Python PlotUtilities.variable_string怎么用?Python PlotUtilities.variable_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeneralUtil.python.PlotUtilities
的用法示例。
在下文中一共展示了PlotUtilities.variable_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_metric_plot
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import variable_string [as 别名]
def make_metric_plot(metrics,
xlim_dist=[1e-5,2],
xlim_load=[1e-2,1e5],
xlim_rupture=[-120,320]):
colors = Plotting.algorithm_colors()
n_rows = 3
n_cols = 3
legend_locs = ['upper right','upper left','upper left']
titles = ["FEATHER","Fovea","Wavelet"]
legend_loading = [None,None,None]
legend_kwargs_style = dict(fontsize=8,handlelength=0.75,handletextpad=0.25)
for i,m in enumerate(metrics):
offset = n_rows * i
# the first column gets the algorithm label; the first row gets the
# metric label
kw_tmp = dict(title_kwargs=dict(fontweight='bold',color='b',fontsize=9),
legend_kwargs=legend_kwargs_style)
if offset == 0:
title_dist = "Location error"
title_load = r"Loading rate (NuG2 + $\mathbf{\alpha_3}$D)"
title_rupture_force = r"Rupture force (NuG2 + $\mathbf{\alpha_3}$D)"
else:
title_dist,title_load,title_rupture_force = "","",""
# only have an x label on the last row
last_row = (offset/n_rows == n_rows-1)
if (last_row):
xlabel_dist = "Relative Error ($\mathbf{x_k}$)"
xlabel_load = "Loading Rate (pN/s)"
xlabel_rupture_force = \
PlotUtilities.variable_string("F_R")
else:
xlabel_dist, xlabel_load,xlabel_rupture_force = "","",""
n_string = r"N_{\mathrm{" + "{:s}".format(titles[i]) + "}}"
ylabel_dist = PlotUtilities.variable_string(n_string)
color_pred=colors[i]
color_true = 'g'
# get the formatting dictionaries for the various plots
distance_histogram_kw= \
Plotting.event_error_kwargs(m,color_pred=color_pred,
label_bool=False)
true_style_histogram = Plotting.\
_histogram_true_style(color_true=color_true,label="true")
pred_style_histogram = Plotting.\
_histogram_predicted_style(color_pred=color_pred,label="predicted")
# get the binning for the rupture force and loading rates
true,pred = m.true,m.pred
ruptures_true,loading_true = \
Learning.get_rupture_in_pN_and_loading_in_pN_per_s(true)
ruptures_pred,loading_pred = \
Learning.get_rupture_in_pN_and_loading_in_pN_per_s(pred)
_lim_force_plot,_bins_rupture_plot,_lim_load_plot,_bins_load_plot = \
Learning.limits_and_bins_force_and_load(ruptures_pred,ruptures_true,
loading_true,loading_pred,
limit=False)
# # make the 'just the distance' figures
ax_dist = plt.subplot(n_rows,n_cols,(offset+1))
Plotting.histogram_event_distribution(use_q_number=True,
**distance_histogram_kw)
PlotUtilities.lazyLabel(xlabel_dist,ylabel_dist,title_dist,
loc=legend_locs[i],legendBgColor='w',
frameon=False,**kw_tmp)
PlotUtilities.ylabel(ylabel_dist,fontweight='bold')
plt.xlim(xlim_dist)
if not last_row:
PlotUtilities.no_x_label(ax_dist)
tick_style_log()
# # make the loading rate histogram
ax_load = plt.subplot(n_rows,n_cols,(offset+2))
Plotting.loading_rate_histogram(pred,bins=_bins_load_plot,
**pred_style_histogram)
Plotting.loading_rate_histogram(true,bins=_bins_load_plot,
**true_style_histogram)
plt.xscale('log')
plt.yscale('log')
PlotUtilities.lazyLabel(xlabel_load,"",title_load,
legendBgColor='w',
loc='upper left',frameon=False,**kw_tmp)
plt.xlim(xlim_load)
if not last_row:
PlotUtilities.no_x_label(ax_load)
# get the locations
if legend_loading[i] is not None:
PlotUtilities.legend(loc=(legend_loading[i]),**legend_kwargs_style)
PlotUtilities.no_y_label(ax_load)
tick_style_log()
# # make the rupture force histogram
ax_rupture = plt.subplot(n_rows,n_cols,(offset+3))
Plotting.rupture_force_histogram(pred,bins=_bins_rupture_plot,
**pred_style_histogram)
Plotting.rupture_force_histogram(true,bins=_bins_rupture_plot,
**true_style_histogram)
PlotUtilities.lazyLabel(xlabel_rupture_force,"",title_rupture_force,
useLegend=False,**kw_tmp)
plt.xlim(xlim_rupture)
plt.yscale('log')
if not last_row:
PlotUtilities.no_x_label(ax_rupture)
PlotUtilities.no_y_label(ax_rupture)
tick_style_log(change_x=False)
# set all the y limits for this row
#.........这里部分代码省略.........
示例2: plot_landscape
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import variable_string [as 别名]
def plot_landscape(data,xlim,kw_landscape=dict(),plot_derivative=True,
zero_q=True,
label_deltaG = PlotUtilities.variable_string("\Delta G")):
landscape_kcal_per_mol = data.mean_landscape_kcal_per_mol
landscape_kcal_per_mol -= min(landscape_kcal_per_mol)
std_landscape_kcal_per_mol = data.std_landscape_kcal_per_mol
extension_nm = data._extension_grid_nm
if (zero_q):
extension_nm -= min(extension_nm)
extension_aa = data.amino_acids_per_nm() * extension_nm
grad = lambda x: np.gradient(x)/(np.gradient(extension_aa))
delta_landscape_kcal_per_mol_per_amino_acid = grad(landscape_kcal_per_mol)
landscape_upper = landscape_kcal_per_mol+std_landscape_kcal_per_mol
landscape_lower =landscape_kcal_per_mol-std_landscape_kcal_per_mol
delta_landscape_kcal_per_mol_per_amino_acid = \
data.mean_delta_landscape_kcal_per_mol_per_AA
std_delta_landscape_kcal_per_mol_per_AA = \
data.std_delta_landscape_kcal_per_mol_per_AA
upper_delta_landscape = delta_landscape_kcal_per_mol_per_amino_acid+\
std_delta_landscape_kcal_per_mol_per_AA
lower_delta_landscape = delta_landscape_kcal_per_mol_per_amino_acid-\
std_delta_landscape_kcal_per_mol_per_AA
# make a second axis for the number of ammino acids
limits_delta = [min(delta_landscape_kcal_per_mol_per_amino_acid),
max(delta_landscape_kcal_per_mol_per_amino_acid)]
limits_energy = [min(landscape_kcal_per_mol),max(landscape_kcal_per_mol)]
units_energy_delta = label_deltaG + \
r" per AA (kcal/(mol $\cdot$ AA))"
units_energy = PlotUtilities.unit_string("\Delta G","kcal/mol")
difference_color = 'rebeccapurple'
landscape_color = kw_landscape['color']
if (plot_derivative):
PlotUtilities.lazyLabel("Extension (nm)",units_energy_delta,"")
PlotUtilities.ylabel(units_energy_delta,color=difference_color)
else:
PlotUtilities.lazyLabel("Extension (nm)","","")
PlotUtilities.ylabel(units_energy,color=landscape_color)
# the derivative goes on the main axis in this case...
if (plot_derivative):
ax_delta = plt.gca()
ax_2 = PlotUtilities.secondAxis(ax_delta,
label=units_energy,color=landscape_color,
limits=limits_energy,secondY =True,
tick_color=landscape_color)
ax_energy = ax_2
to_ret = ax_delta,ax_energy
else:
ax_energy = plt.gca()
ax_delta = None
to_ret = ax_energy
# filter the data if we need to
if (xlim is not None and xlim[1] is not None):
idx= np.where( (extension_nm > xlim[0]) & (extension_nm < xlim[1]))
else:
idx =np.arange(extension_nm.size)
# plot the landscape and its standard deviation
ax_energy.plot(extension_nm[idx],landscape_kcal_per_mol[idx],
label=label_deltaG,zorder=10,**kw_landscape)
ax_energy.fill_between(x=extension_nm[idx],
y1=landscape_lower[idx],
y2=landscape_upper[idx],
alpha=0.15,zorder=10,**kw_landscape)
# the energy y label should be rotated if it is on the right
rotation = -90
if plot_derivative:
kw_y = dict(rotation=-90,x=-0.3)
else:
kw_y = dict()
PlotUtilities.ylabel(ax=ax_energy,lab=units_energy,**kw_y)
# move the y label to the right slightly i we are using both axes
if plot_derivative:
ax_energy.yaxis.set_label_coords(1.2,0.5)
if (plot_derivative):
# plot the energy delta and its bounds, based on the bounds on the
# landscape
ax_delta.plot(extension_nm[idx],
delta_landscape_kcal_per_mol_per_amino_acid[idx],
color=difference_color,linestyle='-',linewidth=1.5)
PlotUtilities.color_axis_ticks(color=landscape_color,ax=ax_energy,
spine_name='right')
ax_delta.fill_between(x=extension_nm[idx],
y1=lower_delta_landscape[idx],
y2=upper_delta_landscape[idx],
alpha=0.15,color=difference_color)
return to_ret
示例3: run
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import variable_string [as 别名]
def run():
"""
<Description>
Args:
param1: This is the first param.
Returns:
This is a description of what is returned.
"""
data_file = "../_Data/example_protein.pkl"
data = CheckpointUtilities.lazy_load(data_file)
# get the 'raw' no-event probabilities, and the increasingly domain-specific
# ones
threshold = 1e-3
pred_kw = dict(threshold=threshold)
split_fec_no_domain_specific,info_no_domain_specific= \
Detector._predict_full(data,f_refs=[],**pred_kw)
_,info_remove_adhesions = Detector._predict_full(data,\
f_refs=[Detector.adhesion_mask_function_for_split_fec],**pred_kw)
_,info_final = Detector._predict_full(data,**pred_kw)
# get the plotting versions of the time, etc
time= split_fec_no_domain_specific.retract.Time
time_plot = time - time[0]
final_event_time = time_plot[info_final.event_idx[-1]]
xlim_time = [0,final_event_time*1.1]
force_plot = split_fec_no_domain_specific.retract.Force * 1e12
force_interp_plot = \
split_fec_no_domain_specific.retract_spline_interpolator()(time) * 1e12
# plot everything
raw_force_kwargs = dict(color='k',alpha=0.3)
interp_force_kwargs = dict(color='b',linewidth=1.25)
probability_kwargs = dict(color='r',linestyle="-",linewidth=0.75)
# for the probabilities, how far from the maximum y the scale bar should be
# (units [0,1]
y_frac_prob = 0.3
common_scale_dict = dict(width=0.1,unit="ms",
unit_kwargs=dict(value_function=lambda x: 1e3 * x))
fec_scale_dict = dict(offset_y=0.5,offset_x=0.15,**common_scale_dict)
prob_scale_dict = dict(**fec_scale_dict)
prob_scale_dict['offset_y'] = y_frac_prob
n_cols = 1
n_rows = 6
ylim_force_pN = [-35,max(force_interp_plot)+1.1+75]
to_prob_plot = lambda x: np.log10(x)
ylim_prob = [to_prob_plot(min((info_final.cdf))/5),1.1]
title_kwargs = dict(loc='left',color='b')
kwargs_axis = dict()
kw = dict(title_kwargs=title_kwargs,axis_kwargs=kwargs_axis)
arrow = "$\Downarrow$"
prob_str = PlotUtilities.variable_string("P")
force_str = PlotUtilities.unit_string("F")
probability_label = "log$_{\mathbf{10}}$" + "({:s})".format(prob_str)
probability_label_post = probability_label
n_cols = 3
n_rows = 6
force_label = "{:s} (pN)".format(force_str)
gs = gridspec.GridSpec(nrows=n_rows,ncols=n_cols,
width_ratios=[1 for _ in range(n_cols)],
height_ratios=[0.75,0.75,0.75,0.75,1,1])
fig = PlotUtilities.figure(figsize=(3.25,4.25))
# plot the 'raw' force and spline
ax_raw = plt.subplot(gs[0,:])
plt.plot(time_plot,force_plot,label="Raw",**raw_force_kwargs)
plt.plot(time_plot,force_interp_plot,label="Spline",
**interp_force_kwargs)
PlotUtilities.x_label_on_top(ax_raw)
PlotUtilities.no_x_label(ax_raw)
plt.ylim(ylim_force_pN)
PlotUtilities.lazyLabel("Time (s)",force_label,"",loc="upper center",
legend_kwargs=dict(handlelength=0.75,ncol=2),
**kw)
plt.xlim(xlim_time)
Scalebar.x_scale_bar_and_ticks_relative(ax=ax_raw,**fec_scale_dict)
tick_style()
# # plot the 'raw' probability
ax_raw_prob = plt.subplot(gs[1,:])
plt.plot(time_plot,to_prob_plot(info_no_domain_specific.cdf),
**probability_kwargs)
title_prob = arrow + "Determine probability of no event"
PlotUtilities.lazyLabel("",probability_label,title_prob,**kw)
PlotUtilities.no_x_label(ax_raw_prob)
plt.ylim(ylim_prob)
plt.xlim(xlim_time)
Scalebar.x_scale_bar_and_ticks_relative(ax=ax_raw_prob,**prob_scale_dict)
tick_style()
# # plot the adhesion-fixed probability
ax_adhesion = plt.subplot(gs[2,:])
plt.plot(time_plot,to_prob_plot(info_remove_adhesions.cdf),
**probability_kwargs)
title_adhesion = arrow + r"Suppress adhesion, stretching"
PlotUtilities.lazyLabel("",probability_label_post,title_adhesion,**kw)
PlotUtilities.no_x_label(ax_adhesion)
plt.ylim(ylim_prob)
plt.xlim(xlim_time)
Scalebar.x_scale_bar_and_ticks_relative(ax=ax_adhesion,
**prob_scale_dict)
tick_style()
# # plot the final probability
ax_final_prob = plt.subplot(gs[3,:])
#.........这里部分代码省略.........
示例4: kwargs_labels
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import variable_string [as 别名]
def kwargs_labels():
second_deriv = r"\frac{1}{2\beta}\ln(1-\frac{\ddot{A}}{k})"
return [PlotUtilities.variable_string(r"A"),
PlotUtilities.variable_string(r"\frac{\dot{A}^2}{2k}"),
PlotUtilities.variable_string(second_deriv)]