本文整理汇总了Python中GeneralUtil.python.PlotUtilities.colorbar方法的典型用法代码示例。如果您正苦于以下问题:Python PlotUtilities.colorbar方法的具体用法?Python PlotUtilities.colorbar怎么用?Python PlotUtilities.colorbar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeneralUtil.python.PlotUtilities
的用法示例。
在下文中一共展示了PlotUtilities.colorbar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: smart_colorbar
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import colorbar [as 别名]
def smart_colorbar(im,ax=plt.gca(),fig=plt.gcf(),
divider_kw=dict(size="5%",pad=0.1),
label="Height (nm)",add_space_only=False):
"""
Makes a color bar on the given axis/figure by moving the axis over a little
"""
# make a separate axis for the colorbar
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.1)
if (not add_space_only):
PlotUtilities.colorbar(label,fig=fig,
bar_kwargs=dict(mappable=im,cax=cax))
else:
cax.axis('off')
示例2: MakePlot
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import colorbar [as 别名]
def MakePlot(SurfaceImage,label,OutPath,**kwargs):
"""
Makes a simple plot of the desired distribution
"""
# make plots
fig = PlotUtilities.figure(figsize=(10/1.5,16/1.5))
ax = plt.subplot(2,1,1)
ImageUtil.PlotImage(SurfaceImage,**kwargs)
PlotUtilities.lazyLabel(r"Microns",r"Microns",label)
PlotUtilities.colorbar("Height (nm)")
ax = plt.subplot(2,1,2)
bins_tmp = ImageUtil.PlotImageDistribution(SurfaceImage)
PlotUtilities.lazyLabel("Height above surface(nm)",
"Count","Distribution of Heights")
PlotUtilities.savefig(fig,OutPath)
return bins_tmp
示例3: run
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import colorbar [as 别名]
def run():
"""
<Description>
Args:
param1: This is the first param.
Returns:
This is a description of what is returned.
"""
base = FEC_Util.default_data_root()
input_directory = base + \
"4Patrick/CuratedData/Outreach/2017-JILA-photo-contest/"
files = GenUtilities.getAllFiles(input_directory,ext=".ibw")
# read all the ibw files in and cache them
images = []
func = PxpLoader.read_ibw_as_image
for i,f in enumerate(files):
cache_file = "./{:d}.pkl".format(i)
tmp = CheckpointUtilities.getCheckpoint(cache_file,func,False,f)
images.append(tmp)
crop = [ None,None,None,None,None,None,None,None ]
for i,image in enumerate(images):
fig = PlotUtilities.figure()
vmin,vmax = np.percentile(image.height_nm_rel(),[75,99])
range_plot_nanometers = 1000 * image.range_microns()
vmin_dict = dict(vmin=vmin,vmax=vmax)
ImageUtil.PlotImage(image,cmap=plt.cm.gray,
range_plot=range_plot_nanometers,**vmin_dict)
PlotUtilities.FormatImageAxis()
PlotUtilities.colorbar("Height (nm)")
pixel_size_meters = image.pixel_size_meters
pixel_size_nanometers = pixel_size_meters * 1e9
print(pixel_size_nanometers,range_plot_nanometers)
scalebar = ScaleBar(pixel_size_nanometers,'nm',box_alpha=0.7)
plt.gca().add_artist(scalebar)
PlotUtilities.savefig(fig,"{:d}.pdf".format(i))
示例4: MakeIwtPlot
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import colorbar [as 别名]
def MakeIwtPlot(OutDir,ExpectedContourLength,Corrected):
"""
Makes an inverse Weierstrass plot and a 2-D heat map of all the data
Args:
OutDir: base directory to save the plot into
ExpectedContourLength:
Corrected: output of GetCorrectedFECs, ie: tuple of (approach,retract)
"""
# get the IWT transform
IwtObjs = []
for _,RetractRaw in Corrected:
retract = FEC_Util.GetFECPullingRegion(RetractRaw,FlipSign=False)
retract.Separation -= retract.Separation[0]
Args = dict(Time=retract.Time,
Extension=retract.Separation,
Force=retract.Force,
SpringConstant=retract.SpringConstant,
Velocity=retract.Velocity)
tmp = InverseWeierstrass.FEC_Pulling_Object(**Args)
IwtObjs.append(tmp)
Landscape = InverseWeierstrass.FreeEnergyAtZeroForce(IwtObjs,NumBins=400)
# Convert the data to format for display as a 2-D heat map
FlatX = np.concatenate([x.Extension for x in IwtObjs])
FlatY = np.concatenate([x.Force for x in IwtObjs])
# plotting beautification
MinX = min(FlatX)
BinsXandY = [400,80]
# N * L0,expected, should be enough to get through overstretching
MaxX = 3*ExpectedContourLength
fudge = (MaxX-MinX)/20
# limits and unit conversions
ToPlotX = lambda x: x*1e9
xlim = lambda: plt.xlim([ToPlotX(MinX),ToPlotX(MaxX)])
EnergyPerKt = Landscape.EnergyLandscape*Landscape.Beta
LandscapeExtensionsPlot = ToPlotX(Landscape.Extensions)
# go to nm and pN for the histogram
HistogramX = ToPlotX(FlatX)
HistogramY = FlatY * 1e12
# make a heat map of everything, no color bar this time
fig = pPlotUtil.figure(figsize=(12,12))
PlotHeatMap(Bins=BinsXandY,X=HistogramX,Y=HistogramY,
ContourLengthNm=ToPlotX(ExpectedContourLength))
xlim()
pPlotUtil.lazyLabel("Separation (nm)","Force (pN)","FEC Heat Map",
legendBgColor='w',frameon=True)
pPlotUtil.colorbar("Count in bins")
pPlotUtil.savefig(fig,"{:s}Out/HeatMap.png".format(OutDir))
# make a new figure, also add the heatmap
fig = pPlotUtil.figure(figsize=(12,18))
plt.subplot(3,1,1)
PlotHeatMap(Bins=BinsXandY,X=HistogramX,Y=HistogramY,
ContourLengthNm=ToPlotX(ExpectedContourLength))
xlim()
pPlotUtil.lazyLabel("","Force (pN)","",frameon=True,legendBgColor='w')
plt.subplot(3,1,2)
plt.plot(LandscapeExtensionsPlot,EnergyPerKt)
pPlotUtil.lazyLabel("","Free Energy (kT)","")
xlim()
plt.subplot(3,1,3)
Grad = np.gradient(EnergyPerKt)
plt.plot(LandscapeExtensionsPlot,Grad)
xlim()
# avoid super negative spikes
plt.ylim([-max(Grad),max(Grad)])
pPlotUtil.lazyLabel("Extension (nm)","Free Energy Difference (kT)","")
pPlotUtil.savefig(fig,"{:s}Out/IWT.png".format(OutDir))
示例5: MakeGridPlot
# 需要导入模块: from GeneralUtil.python import PlotUtilities [as 别名]
# 或者: from GeneralUtil.python.PlotUtilities import colorbar [as 别名]
def MakeGridPlot(ImageInfo,Limits,Base,Name,figsize,Force=False,
ImageFunc=lambda m_list: m_list[0],hist_kwargs=dict()):
"""
Given a list of images, files, and labels, makes a gridwise comparison
Args:
ImageInfo: Tuple of <FileName,Label,plotkwargs>
Limits: x Limits for the histogram
Base: Base directory (where in and out live
figsize: how big to make the grid figure
Force: if true, force re-reading
ImageFunc: given a list of images from the file, selects one and
only one
"""
# first, loop through and make the 'normal' plots, per distribution
Images = []
OutBase = Base + "out/"
InBase = Base + "in/"
max_n = 0
for i,(file_name,label,kwargs) in enumerate(ImageInfo):
List = CheckpointUtilities.getCheckpoint(OutBase +"c_"+label+".pkl",
ReadImageAsObject,Force,
InBase + file_name)
Image = ImageFunc(List)
n,bins,patches = \
MakePlot(Image,label,OutPath=OutBase + str(i)+"_" +label + ".pdf",
**kwargs)
max_n = max(max_n,max(n))
Images.append(Image)
# now we make a grid
NumRows = 4
NumCols = len(ImageInfo)
gs = gridspec.GridSpec(NumRows, NumCols)
bins = []
fig = PlotUtilities.figure(figsize=figsize)
colors = ['r','g','b','k','m','c','y']
for i in range(NumCols):
im = Images[i]
color_idx= i % len(colors)
label,kwargs = ImageInfo[i][1:]
# plot these next to each other
ax = plt.subplot(gs[0,i])
ImageUtil.PlotImage(im,**kwargs)
if (i ==0 ):
PlotUtilities.lazyLabel(r"Microns",r"Microns",label)
PlotUtilities.colorbar("Height (nm)")
else:
PlotUtilities.lazyLabel(r"","",label)
PlotUtilities.colorbar("")
ax = plt.subplot(gs[1,i])
bins_tmp = ImageUtil.PlotImageDistribution(im,color=colors[color_idx])
plt.xlim(Limits)
# set common y limits
plt.ylim(0.5,2*max_n)
bins.append(bins_tmp)
# only add the x and y labels to the first plot, to de-clutter
if (i == 0):
PlotUtilities.lazyLabel("Height above surface(nm)",
"Count","Distribution of Heights")
else:
# just get the axis formatting
PlotUtilities.lazyLabel("","","")
ax = plt.subplot(gs[2, :])
labels = [i[1] for i in ImageInfo]
for i,im in enumerate(Images):
color_idx = i % len(colors)
ImageUtil.PlotImageDistribution(im,label=labels[i],
color=colors[color_idx],
PlotLines=False,**hist_kwargs)
plt.xlim(Limits)
PlotUtilities.lazyLabel("Height above surface(nm)",
"Count","Distribution of Heights")
ax = plt.subplot(gs[3,:])
data = [i.height_nm_rel() for i in Images]
x_vals = np.arange(len(data))
# (1) show the 5-95 by the notches, *dont* show any outliers (too slow)
# (2) show the median line
box = plt.boxplot(data,positions=x_vals,whis=[5,95],sym='',
patch_artist=True)
plt.xticks(x_vals, labels,rotation=0,)
PlotUtilities.lazyLabel("","Height (nm)",
"Comparison of Image Distributions")
# set the alpha and colors
for patch, color in zip(box['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.3)
# finally, plot the mean and standard deviations as a functo
PlotUtilities.savefig(fig,OutBase+ "Grid_" + Name+".pdf")