本文整理匯總了Python中pylab.gca方法的典型用法代碼示例。如果您正苦於以下問題:Python pylab.gca方法的具體用法?Python pylab.gca怎麽用?Python pylab.gca使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylab
的用法示例。
在下文中一共展示了pylab.gca方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot_confusion_matrix
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def plot_confusion_matrix(y_true, y_pred, size=None, normalize=False):
"""plot_confusion_matrix."""
cm = confusion_matrix(y_true, y_pred)
fmt = "%d"
if normalize:
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
fmt = "%.2f"
xticklabels = list(sorted(set(y_pred)))
yticklabels = list(sorted(set(y_true)))
if size is not None:
plt.figure(figsize=(size, size))
heatmap(cm, xlabel='Predicted label', ylabel='True label',
xticklabels=xticklabels, yticklabels=yticklabels,
cmap=plt.cm.Blues, fmt=fmt)
if normalize:
plt.title("Confusion matrix (norm.)")
else:
plt.title("Confusion matrix")
plt.gca().invert_yaxis()
示例2: test_lines_dists
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def test_lines_dists():
import pylab
ax = pylab.gca()
xs, ys = (0,30), (20,150)
pylab.plot(xs, ys)
points = list(zip(xs, ys))
p0, p1 = points
xs, ys = (0,0,20,30), (100,150,30,200)
pylab.scatter(xs, ys)
dist = line2d_seg_dist(p0, p1, (xs[0], ys[0]))
dist = line2d_seg_dist(p0, p1, np.array((xs, ys)))
for x, y, d in zip(xs, ys, dist):
c = Circle((x, y), d, fill=0)
ax.add_patch(c)
pylab.xlim(-200, 200)
pylab.ylim(-200, 200)
pylab.show()
示例3: test_lines_dists
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def test_lines_dists():
import pylab
ax = pylab.gca()
xs, ys = (0,30), (20,150)
pylab.plot(xs, ys)
points = zip(xs, ys)
p0, p1 = points
xs, ys = (0,0,20,30), (100,150,30,200)
pylab.scatter(xs, ys)
dist = line2d_seg_dist(p0, p1, (xs[0], ys[0]))
dist = line2d_seg_dist(p0, p1, np.array((xs, ys)))
for x, y, d in zip(xs, ys, dist):
c = Circle((x, y), d, fill=0)
ax.add_patch(c)
pylab.xlim(-200, 200)
pylab.ylim(-200, 200)
pylab.show()
示例4: plot_regions
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def plot_regions(self, fill=True, bgimage=None, alpha=0.5):
import pylab as pl
ax = pl.gca()
assert isinstance(ax, pl.Axes)
colors = i12.JET_12
self._plot_background(bgimage)
for label in self.regions:
color = colors[i12.LABELS.index(label)] / 255.
for region in self.regions[label]:
t = region['top']
l = self.facade_left + region['left']
b = region['bottom']
r = self.facade_left + region['right']
patch = pl.Rectangle((l, t), r - l, b - t, color=color, fill=fill, alpha=alpha)
ax.add_patch(patch)
示例5: impose_legend_limit
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def impose_legend_limit(limit=30, axes="gca", **kwargs):
"""
This will erase all but, say, 30 of the legend entries and remake the legend.
You'll probably have to move it back into your favorite position at this point.
"""
if axes=="gca": axes = _pylab.gca()
# make these axes current
_pylab.axes(axes)
# loop over all the lines_pylab.
for n in range(0,len(axes.lines)):
if n > limit-1 and not n==len(axes.lines)-1: axes.lines[n].set_label("_nolegend_")
if n == limit-1 and not n==len(axes.lines)-1: axes.lines[n].set_label("...")
_pylab.legend(**kwargs)
示例6: image_click_xshift
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def image_click_xshift(axes = "gca"):
"""
Takes a starting and ending point, then shifts the image y by this amount
"""
if axes == "gca": axes = _pylab.gca()
try:
p1 = _pylab.ginput()
p2 = _pylab.ginput()
xshift = p2[0][0]-p1[0][0]
e = axes.images[0].get_extent()
e[0] = e[0] + xshift
e[1] = e[1] + xshift
axes.images[0].set_extent(e)
_pylab.draw()
except:
print("whoops")
示例7: image_shift
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def image_shift(xshift=0, yshift=0, axes="gca"):
"""
This will shift an image to a new location on x and y.
"""
if axes=="gca": axes = _pylab.gca()
e = axes.images[0].get_extent()
e[0] = e[0] + xshift
e[1] = e[1] + xshift
e[2] = e[2] + yshift
e[3] = e[3] + yshift
axes.images[0].set_extent(e)
_pylab.draw()
示例8: image_set_clim
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def image_set_clim(zmin=None, zmax=None, axes="gca"):
"""
This will set the clim (range) of the colorbar.
Setting zmin or zmax to None will not change them.
Setting zmin or zmax to "auto" will auto-scale them to include all the data.
"""
if axes=="gca": axes=_pylab.gca()
image = axes.images[0]
if zmin=='auto': zmin = _n.min(image.get_array())
if zmax=='auto': zmax = _n.max(image.get_array())
if zmin==None: zmin = image.get_clim()[0]
if zmax==None: zmax = image.get_clim()[1]
image.set_clim(zmin, zmax)
_pylab.draw()
示例9: reverse_draw_order
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def reverse_draw_order(axes="current"):
"""
This function takes the graph and reverses the draw order.
"""
if axes=="current": axes = _pylab.gca()
# get the lines from the plot
lines = axes.get_lines()
# reverse the order
lines.reverse()
for n in range(0, len(lines)):
if isinstance(lines[n], _mpl.lines.Line2D):
axes.lines[n]=lines[n]
_pylab.draw()
示例10: scale_x
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def scale_x(scale, axes="current"):
"""
This function scales lines horizontally.
"""
if axes=="current": axes = _pylab.gca()
# get the lines from the plot
lines = axes.get_lines()
# loop over the lines and trim the data
for line in lines:
if isinstance(line, _mpl.lines.Line2D):
line.set_xdata(_pylab.array(line.get_xdata())*scale)
# update the title
title = axes.title.get_text()
title += ", x_scale="+str(scale)
axes.title.set_text(title)
# zoom to surround the data properly
auto_zoom()
示例11: set_all_line_attributes
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def set_all_line_attributes(attribute="lw", value=2, axes="current", refresh=True):
"""
This function sets all the specified line attributes.
"""
if axes=="current": axes = _pylab.gca()
# get the lines from the plot
lines = axes.get_lines()
# loop over the lines and trim the data
for line in lines:
if isinstance(line, _mpl.lines.Line2D):
_pylab.setp(line, attribute, value)
# update the plot
if refresh: _pylab.draw()
示例12: line_math
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def line_math(fx=None, fy=None, axes='gca'):
"""
applies function fx to all xdata and fy to all ydata.
"""
if axes=='gca': axes = _pylab.gca()
lines = axes.get_lines()
for line in lines:
if isinstance(line, _mpl.lines.Line2D):
xdata, ydata = line.get_data()
if not fx==None: xdata = fx(xdata)
if not fy==None: ydata = fy(ydata)
line.set_data(xdata,ydata)
_pylab.draw()
示例13: render_sdf
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def render_sdf(obj_, object_name_):
plt.figure()
# ax = h.add_subplot(111, projection='3d')
# surface_points = np.where(np.abs(sdf.sdf_values) < thresh)
# surface_points = np.array(surface_points)
# surface_points = surface_points[:, np.random.choice(surface_points[0].size, 3000, replace=True)]
# # from IPython import embed; embed()
surface_points = obj_.sdf.surface_points()[0]
surface_points = np.array(surface_points)
ind = np.random.choice(np.arange(len(surface_points)), 1000)
x = surface_points[ind, 0]
y = surface_points[ind, 1]
z = surface_points[ind, 2]
ax = plt.gca(projection=Axes3D.name)
ax.scatter(x, y, z, '.', s=np.ones_like(x) * 0.3, c='b')
ax.set_xlim3d(0, obj_.sdf.dims_[0])
ax.set_ylim3d(0, obj_.sdf.dims_[1])
ax.set_zlim3d(0, obj_.sdf.dims_[2])
plt.title(object_name_)
plt.show()
示例14: plot
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def plot(ifile, varkey, options, before='', after=''):
import pylab as pl
outpath = getattr(options, 'outpath', '.')
var = ifile.variables[varkey]
dims = [(k, l) for l, k in zip(var[:].shape, var.dimensions) if l > 1]
if len(dims) > 1:
raise ValueError(
'Plots can have only 1 non-unity dimensions; got %d - %s' %
(len(dims), str(dims)))
exec(before)
ax = pl.gca()
print(varkey, end='')
if options.logscale:
ax.set_yscale('log')
ax.plot(var[:].squeeze())
ax.set_xlabel('unknown')
ax.set_ylabel(getattr(var, 'standard_name',
varkey).strip() + ' ' + var.units.strip())
fmt = 'png'
figpath = os.path.join(outpath + '_1d_' + varkey + '.' + fmt)
exec(after)
pl.savefig(figpath)
print('Saved fig', figpath)
return figpath
示例15: drawPrfast
# 需要導入模塊: import pylab [as 別名]
# 或者: from pylab import gca [as 別名]
def drawPrfast(tp, fp, tot, show=True, col="g"):
tp = numpy.cumsum(tp)
fp = numpy.cumsum(fp)
rec = tp / tot
prec = tp / (fp + tp)
ap = VOColdap(rec, prec)
ap1 = VOCap(rec, prec)
if show:
pylab.plot(rec, prec, '-%s' % col)
pylab.title("AP=%.1f 11pt(%.1f)" % (ap1 * 100, ap * 100))
pylab.xlabel("Recall")
pylab.ylabel("Precision")
pylab.grid()
pylab.gca().set_xlim((0, 1))
pylab.gca().set_ylim((0, 1))
pylab.show()
pylab.draw()
return rec, prec, ap1