本文整理匯總了Python中matplotlib.pyplot.hold方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.hold方法的具體用法?Python pyplot.hold怎麽用?Python pyplot.hold使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.hold方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot_histograms
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def plot_histograms(file_name, candidate_data_multiple_bands,
reference_data_multiple_bands=None,
# Default is for Blue-Green-Red-NIR:
colour_order=['b', 'g', 'r', 'y'],
x_limits=None, y_limits=None):
logging.info('Display: Creating histogram plot - {}'.format(file_name))
fig = plt.figure()
plt.hold(True)
for colour, c_band in zip(colour_order, candidate_data_multiple_bands):
c_bh, c_bins = numpy.histogram(c_band, bins=256)
plt.plot(c_bins[:-1], c_bh, color=colour, linestyle='-', linewidth=2)
if reference_data_multiple_bands:
for colour, r_band in zip(colour_order, reference_data_multiple_bands):
r_bh, r_bins = numpy.histogram(r_band, bins=256)
plt.plot(
r_bins[:-1], r_bh, color=colour, linestyle='--', linewidth=2)
plt.xlabel('DN')
plt.ylabel('Number of pixels')
if x_limits:
plt.xlim(x_limits)
if y_limits:
plt.ylim(y_limits)
fig.savefig(file_name, bbox_inches='tight')
plt.close(fig)
示例2: getBarycentricCoords
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def getBarycentricCoords(A, B, C, X, checkValidity = True):
T = np.array( [ [A.x - C.x, B.x - C.x ], [A.y - C.y, B.y - C.y] ] )
y = np.array( [ [X.x - C.x], [X.y - C.y] ] )
lambdas = linalg.solve(T, y)
lambdas = lambdas.flatten()
lambdas = np.append(lambdas, 1 - (lambdas[0] + lambdas[1]))
if checkValidity:
if (lambdas[0] < 0 or lambdas[1] < 0 or lambdas[2] < 0):
print "ERROR: Not a convex combination; lambda = %s"%lambdas
print "pointInsideConvexPolygon2D = %s"%pointInsideConvexPolygon2D([A, B, C], X, 0)
plt.plot([A.x, B.x, C.x, A.x], [A.y, B.y, C.y, A.y], 'r')
plt.hold(True)
plt.plot([X.x], [X.y], 'b.')
plt.show()
assert (lambdas[0] >= 0 and lambdas[1] >= 0 and lambdas[2] >= 0)
else:
lambdas[0] = max(lambdas[0], 0)
lambdas[1] = max(lambdas[1], 0)
lambdas[2] = max(lambdas[2], 0)
return lambdas
示例3: plot_traj
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def plot_traj(w, w_true, fname=None):
""" Plot the trajectory of the filter coefficients
Inputs:
w: matrix of filter weights versus time
w_true: vector of true filter weights
fname: what filename to export the figure to. If None, then doesn't
export
"""
plt.figure()
n = np.arange(w.shape[0])
n_ones = np.ones(w.shape[0])
plt.hold(True)
# NOTE: This construction places a limit of 4 on the filter order
plt_colors = ['b', 'r', 'g', 'k']
for p in xrange(w.shape[1]):
plt.plot(n, w[:,p], '{}-'.format(plt_colors[p]), label='w({})'.format(p))
plt.plot(n, w_true[p] * n_ones, '{}--'.format(plt_colors[p]))
plt.xlabel('Iteration')
plt.ylabel('Coefficients')
plt.legend()
if fname:
plt.savefig(fname)
plt.close()
示例4: hist
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def hist(data):
"""Convenience method to do all the plotting gymnastics to get a resonable
looking histogram plot.
Input: data - numpy array in gdal format - (bands, x, y)
Returns: matplotlib figure handle
Adapted from:
http://nbviewer.jupyter.org/github/HyperionAnalytics/PyDataNYC2014/blob/master/color_image_processing.ipynb
"""
fig = plt.figure()
ax1 = fig.add_subplot(111)
plt.hold(True)
for x in xrange(len(data[:,0,0])):
counts, edges = np.histogram(data[x,:,:],bins=100)
centers = [(edges[i]+edges[i+1])/2.0 for i,v in enumerate(edges[:-1])]
ax1.plot(centers,counts)
plt.hold(False)
plt.show(block=False)
# return fig
示例5: animate_series
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def animate_series(fk, M, N, xmin, xmax, ymin, ymax, n, exact, exactname):
x = np.linspace(xmin, xmax, n)
s = np.zeros(len(x))
counter = 1
for k in range(M, N + 1):
s += fk(x, k)
plt.plot(x, s, linewidth=2, color='#67001f')
plt.hold(1)
plt.plot(x, exact(x), '--', linewidth=2, color='#053061')
plt.hold(0)
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.legend(['Taylor series approximation - %d terms' %
counter, exactname])
plt.savefig('tmp_%04d.png' % counter)
counter += 1
示例6: animate_orbit
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def animate_orbit(a, b, omega, n):
tlist = np.linspace(0, 2 * np.pi / omega, n)
xorbit, yorbit = orbit_path(tlist, a, b, omega)
counter = 0
for t in tlist:
x, y = orbit_path(t, a, b, omega)
plt.plot(xorbit, yorbit, '--', color='#67001f', linewidth=2)
plt.hold(1)
plt.plot(x, y, 'ro', markerfacecolor='#2166ac',
markeredgecolor='#053061', markeredgewidth=2, markersize=20)
plt.hold(0)
plt.xlim([xorbit.min() * 1.1, xorbit.max() * 1.1])
plt.ylim([yorbit.min() * 1.1, yorbit.max() * 1.1])
plt.xlabel('x')
plt.ylabel('y')
plt.title('Instantaneous velocity = %4f' % inst_vel(t, a, b, omega))
plt.savefig('tmp_%03d.png' % counter)
counter += 1
示例7: animate_series
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def animate_series(fk, N, tmax, n, exact, exactname):
t = np.linspace(0, tmax, n)
s = np.zeros(len(t))
counter = 1
for k in range(0, N + 1):
s = S(t, k, tmax)
plt.plot(t, s, linewidth=2, color='#67001f')
plt.hold(1)
plt.plot(t, exact(t, tmax), '--', linewidth=2, color='#053061')
plt.hold(0)
plt.xlim(0, tmax)
plt.ylim(-1.3, 1.3)
plt.legend(['Sine sum - %d terms' %
counter, exactname])
plt.savefig('tmp_%04d.png' % counter)
counter += 1
示例8: viz_textbb
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def viz_textbb(fignum,text_im, bb_list,alpha=1.0):
"""
text_im : image containing text
bb_list : list of 2x4xn_i boundinb-box matrices
"""
plt.close(fignum)
plt.figure(fignum)
plt.imshow(text_im)
plt.hold(True)
H,W = text_im.shape[:2]
for i in xrange(len(bb_list)):
bbs = bb_list[i]
ni = bbs.shape[-1]
for j in xrange(ni):
bb = bbs[:,:,j]
bb = np.c_[bb,bb[:,0]]
plt.plot(bb[0,:], bb[1,:], 'r', linewidth=2, alpha=alpha)
plt.gca().set_xlim([0,W-1])
plt.gca().set_ylim([H-1,0])
plt.show(block=False)
示例9: fig_memory_usage
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def fig_memory_usage():
# FAST memory
x = [1,3,7,14,30,90,180]
y_fast = [0.653,1.44,2.94,4.97,9.05,19.9,35.2]
# ConvNetQuake
y_convnet = [6.8*1e-5]*7
# Create figure
plt.loglog(x,y_fast,"o-")
plt.hold('on')
plt.loglog(x,y_convnet,"o-")
# plot markers
plt.loglog(x,[1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5],'o')
plt.ylabel("Memory usage (GB)")
plt.xlabel("Continous data duration (days)")
plt.xlim(1,180)
plt.grid("on")
plt.savefig("./figures/memoryusage.eps")
plt.close()
示例10: fig_run_time
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def fig_run_time():
# fast run time
x_fast = [1,3,7,14,30,90,180]
y_fast = [289,1.13*1e3,2.48*1e3,5.41*1e3,1.56*1e4,
6.61*1e4,1.98*1e5]
x_auto = [1,3]
y_auto = [1.54*1e4, 8.06*1e5]
x_convnet = [1,3,7,14,30]
y_convnet = [9,27,61,144,291]
# create figure
plt.loglog(x_auto,y_auto,"o-")
plt.hold('on')
plt.loglog(x_fast[0:5],y_fast[0:5],"o-")
plt.loglog(x_convnet,y_convnet,"o-")
# plot x markers
plt.loglog(x_convnet,[1e0]*len(x_convnet),'o')
# plot y markers
y_markers = [1,60,3600,3600*24]
plt.plot([1]*4,y_markers,'ko')
plt.ylabel("run time (s)")
plt.xlabel("continous data duration (days)")
plt.xlim(1,35)
plt.grid("on")
plt.savefig("./figures/runtimes.eps")
示例11: drawSamples
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def drawSamples(self, nsamples):
import matplotlib.pyplot as plt
plt.figure(1)
plt.clf()
plt.hold(True)
k = ConvexHull(self.bot_pts.T).vertices
k = np.hstack((k, k[0]))
n = self.planar_polyhedron.generators.shape[0]
plt.plot(self.planar_polyhedron.generators.T[0,list(range(n)) + [0]],
self.planar_polyhedron.generators.T[1,list(range(n)) + [0]], 'r.-')
samples = sample_convex_polytope(self.c_space_polyhedron.A,
self.c_space_polyhedron.b,
500)
for i in range(samples.shape[1]):
R = np.array([[np.cos(samples[2,i]), -np.sin(samples[2,i])],
[np.sin(samples[2,i]), np.cos(samples[2,i])]])
V = R.dot(self.bot_pts[:,k])
V = V + samples[:2, i].reshape((2,1))
plt.plot(V[0,:], V[1,:], 'k-')
plt.show()
示例12: make_plots
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def make_plots(xs,ys,labels,title=None,x_name=None,y_name=None,y_bounds=None,save_to=None):
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k')
handles = []
plt.figure()
plt.hold(True)
for i in range(len(labels)):
plot, = make_plot(xs[i],ys[i],color=colors[i%len(colors)],new_fig=False)
handles.append(plot)
plt.legend(handles,labels)
if title is not None:
plt.title(title)
if x_name is not None:
plt.xlabel(x_name)
if y_name is not None:
plt.ylabel(y_name)
if y_bounds is not None:
plt.ylim(y_bounds)
if save_to is not None:
plt.savefig(save_to,bbox_inches='tight')
plt.hold(False)
示例13: doit
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def doit(fn, col1, col2, tag):
train = []
val = []
with open(fn) as f:
for l in f:
if "finished" in l:
sp = l.split()
#clip to 5
# tr = min(float(sp[col1]), 5.0)
# va = min(float(sp[col2]), 5.0)
tr = float(sp[col1])
va = float(sp[col2])
# if tr>1: tr = 1/tr
# if va>1: va = 1/va
train.append(tr)
val.append(va)
plt.plot(train, label="train")
plt.hold(True)
plt.plot(val, label="val")
plt.legend()
plt.title(fn + " " + tag)
#plt.show()
示例14: draw_minutiae
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def draw_minutiae(image, minutiae, fname, saveimage= False, r=15, drawScore=False):
image = np.squeeze(image)
fig = plt.figure()
plt.imshow(image,cmap='gray')
plt.hold(True)
# Check if no minutiae
if minutiae.shape[0] > 0:
plt.plot(minutiae[:, 0], minutiae[:, 1], 'rs', fillstyle='none', linewidth=1)
for x, y, o, s in minutiae:
plt.plot([x, x+r*np.cos(o)], [y, y+r*np.sin(o)], 'r-')
if drawScore == True:
plt.text(x - 10, y - 10, '%.2f' % s, color='yellow', fontsize=4)
plt.axis([0,image.shape[1],image.shape[0],0])
plt.axis('off')
if saveimage:
plt.savefig(fname, dpi=500, bbox_inches='tight', pad_inches = 0)
plt.close(fig)
else:
plt.show()
return
示例15: plot_correlation
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import hold [as 別名]
def plot_correlation(flname, title, x_label, y_label, dataset):
"""
Scatter plot with line of best fit
dataset - tuple of (x_values, y_values)
"""
plt.clf()
plt.hold(True)
plt.scatter(dataset[0], dataset[1], alpha=0.7, color="k")
xs = np.array(dataset[0])
ys = np.array(dataset[1])
A = np.vstack([xs, np.ones(len(xs))]).T
m, c = np.linalg.lstsq(A, ys)[0]
plt.plot(xs, m*xs + c, "c-")
plt.xlabel(x_label, fontsize=16)
plt.ylabel(y_label, fontsize=16)
plt.xlim([0.25, max(dataset[0])])
plt.ylim([10., max(dataset[1])])
plt.title(title, fontsize=18)
plt.savefig(flname, DPI=200)