本文整理汇总了Python中matplotlib.pyplot.fill函数的典型用法代码示例。如果您正苦于以下问题:Python fill函数的具体用法?Python fill怎么用?Python fill使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fill函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: standard_process
def standard_process():
"""
standard process from scikit learn
"""
X = np.atleast_2d([1., 3., 5., 6., 7., 8.]).T
y = f(X).ravel()
x = np.atleast_2d(np.linspace(0, 10, 1000)).T
gp = gaussian_process.GaussianProcess(theta0=1e-2, thetaL=1e-4, thetaU=1e-1)
gp.fit(X, y)
y_pred, MSE = gp.predict(x, eval_MSE=True)
sigma = np.sqrt(MSE)
# Plot the function, the prediction and the 95% confidence interval based on
# the MSE
fig = plt.figure()
plt.plot(x, f(x), 'r:', label=u'$f(x) = x\,\sin(x)$')
plt.plot(X, y, 'r.', markersize=10, label=u'Observations')
plt.plot(x, y_pred, 'b-', label=u'Prediction')
plt.fill(np.concatenate([x, x[::-1]]),
np.concatenate([y_pred - 1.9600 * sigma,
(y_pred + 1.9600 * sigma)[::-1]]),
alpha=.5, fc='b', ec='None', label='95% confidence interval')
plt.xlabel('$x$')
plt.ylabel('$f(x)$')
plt.ylim(-10, 20)
plt.legend(loc='upper left')
plt.show()
示例2: plot_data_and_line
def plot_data_and_line(w1,w2):
w1,w2 = float(w1),float(w2)
if w2 != 0 :
y1,y2 = (-w1*(xl1))/w2, (-w1*(xl2))/w2
vx1,vy1 = [xl1,xl2,xl2,xl1,xl1], [y1,y2,yl2,yl2,y1]
vx2,vy2 = [xl1,xl2,xl2,xl1,xl1], [y1,y2,yl1,yl1,y1]
elif w1 != 0:
vx1,vy1 = [xl2,0,0,xl2,xl2], [yl1,yl1,yl2,yl2,yl1]
vx2,vy2 = [xl1,0,0,xl1,xl1], [yl1,yl1,yl2,yl2,yl1]
else:
print "ERROR, Invalid w1 and w2."
return;
if w2 > 0 or ( w2 == 0 and w1 > 0):
c1,c2 = 'b','r'
else:
c1,c2 = 'r','b'
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(X1[Y > 0], X2[Y > 0], s = 80, c = 'b', marker = "o")
plt.scatter(X1[Y<= 0], X2[Y<= 0], s = 80, c = 'r', marker = "^")
plt.fill(vx1, vy1, c1, alpha = 0.25)
plt.fill(vx2, vy2, c2, alpha = 0.25)
ax.set_title(("w1 = %s, w2 = %s")%( w1, w2))
ax.set_xlim(xl1, xl2)
ax.set_ylim(yl1, yl2)
fig.set_size_inches(6, 6)
plt.show()
示例3: plot_triangle
def plot_triangle(x, y, color=None, draw_lines=True, fill=False):
"""plot an rgb triangle in xy
Args:
x,y (numpy.array): [r, g, b] coords
kwargs:
color (str): if none, 1st point--> red, 2nd --> green, 3rd -> blue
drawLines (bool): draw outline
fill (bool): fill triangle
"""
if fill:
plt.fill(x, y, color='grey', alpha='0.5')
if draw_lines:
indexVal = np.hstack([np.arange(x.size), 0])
plt.plot(x[indexVal], y[indexVal], '-k')
if color:
plt.plot(x[0], y[0], 'o', x[1], y[1], 'o', x[2], y[2], 'o',
color=color)
else:
plt.plot(x[0], y[0], 'or', x[1], y[1], 'og', x[2], y[2], 'ob')
示例4: wiggle
def wiggle (traces, skipt=1,scale=1.,lwidth=.1,offsets=None,redvel=0., manthifts=None, tshift=0.,sampr=1.,clip=10., dx=1., color='black',fill=True,line=True, ax=None):
ns = traces.shape[1]
ntr = traces.shape[0]
t = np.arange(ns)*sampr
timereduce = lambda offsets, redvel, shift: [float(offset) / redvel + shift for offset in offsets]
if (offsets is not None):
shifts = timereduce(offsets, redvel, tshift)
elif (manthifts is not None):
shifts = manthifts
else:
shifts = np.zeros((ntr,))
for i in range(0, ntr, skipt):
trace = traces[i].copy()
trace[0] = 0
trace[-1] = 0
if ax == None:
if (line):
plt.plot(i*dx + clipsign(trace / scale, clip), t - shifts[i], color=color, linewidth=lwidth)
if (fill):
for j in range(ns):
if (trace[j] < 0):
trace[j] = 0
plt.fill(i*dx + clipsign(trace / scale, clip), t - shifts[i], color=color, linewidth=0)
else:
if (line):
ax.plot(i*dx + clipsign(trace / scale, clip), t - shifts[i], color=color, linewidth=lwidth)
if (fill):
for j in range(ns):
if (trace[j] < 0):
trace[j] = 0
ax.fill(i*dx + clipsign(trace / scale, clip), t - shifts[i], color=color, linewidth=0)
示例5: dist_load
def dist_load():
# add distributed load
plt.subplot(3,1,1)
for k in np.linspace(0,L,20):
ax1.arrow(k, 11+L/10, 0, -3, head_width=L*0.01, head_length=L*0.1, fc='k', ec='k')
plt.title('Free Body Diagram')
plt.axis('off') # removes axis and labels
#ax1.set_yticklabels('')
# dist load shear
x = [0,0,L,L]
y = [0,5,-5,0]
plt.subplot(3,1,2)
plt.ylabel('Shear, V')
plt.title('Shear Diagram')
plt.fill(x, y, 'b', alpha=0.25)
plt.grid(True)
plt.xlim([-1, L+1])
# dist load bending
x = np.linspace(-L/2,L/2,100)
y = -(x**2)+(np.max(x**2))
x = np.linspace(0,L,100)
plt.subplot(3,1,3)
plt.title('Bending Diagram')
plt.ylabel('Moment, M')
plt.fill(x, y, 'b', alpha=0.25)
plt.grid(True)
plt.xlim([-1, L+1])
示例6: radar_plot
def radar_plot():
"""
radar plot
"""
# 生成测试数据
labels = np.array(["A组", "B组", "C组", "D组", "E组", "F组"])
data = np.array([68, 83, 90, 77, 89, 73])
theta = np.linspace(0, 2*np.pi, len(data), endpoint=False)
# 数据预处理
data = np.concatenate((data, [data[0]]))
theta = np.concatenate((theta, [theta[0]]))
# 画图方式
plt.subplot(111, polar=True)
plt.title("雷达图", fontproperties=myfont)
# 设置"theta grid"/"radar grid"
plt.thetagrids(theta*(180/np.pi), labels=labels, fontproperties=myfont)
plt.rgrids(np.arange(20, 100, 20), labels=np.arange(20, 100, 20), angle=0)
plt.ylim(0, 100)
# 画雷达图,并填充雷达图内部区域
plt.plot(theta, data, "bo-", linewidth=2)
plt.fill(theta, data, color="red", alpha=0.25)
# 图形显示
plt.show()
return
示例7: hinton
def hinton(W, max_weight=None):
""" Draws a Hinton diagram for visualizing a weight matrix.
"""
if max_weight is None:
max_weight = 2 ** np.ceil(np.log2(np.max(np.abs(W))))
# Temporarily disable matplotlib interactive mode if it is on,
# otherwise this takes forever.
isinteractive = plt.isinteractive()
if isinteractive:
plt.ioff()
height, width = W.shape
plt.clf()
plt.fill(np.array([0, width, width, 0]), np.array([0, 0, height, height]), "gray")
plt.axis("off")
plt.axis("equal")
for (y, x), w in np.ndenumerate(W):
if w != 0:
color = "white" if w > 0 else "black"
area = min(1, np.abs(w) / max_weight)
_blob(x + 0.5, height - y - 0.5, area, color)
if isinteractive:
plt.ion()
示例8: hist_with_peak
def hist_with_peak(x, bins=None, range=None, ax=None, orientation='vertical',
histtype=None, **kwargs):
if ax is None:
ax = plt.gca()
hist, bin_edges = np.histogram(x, bins=bins, range=range)
hist_n = hist * 1.0/hist.max()
width = bin_edges[1] - bin_edges[0]
x = np.ravel(zip(bin_edges[:-1], bin_edges[:-1]+width))
y = np.ravel(zip(hist_n, hist_n))
if histtype == 'step':
if orientation == 'vertical':
plt.plot(x, y, **kwargs)
elif orientation == 'horizontal':
plt.plot(y, x, **kwargs)
else:
raise ValueError
elif histtype == 'stepfilled':
if orientation == 'vertical':
plt.fill(x, y, **kwargs)
elif orientation == 'horizontal':
plt.fill(y, x, **kwargs)
else:
raise ValueError
else:
raise ValueError
示例9: noiseless
def noiseless():
X = np.atleast_2d([1.,3.,5.,6.,7.,8.,]).T
# observations
y = f(X).ravel() # reshape to 1-D
# mesh the input space to cover all points to predict f(x) and the MSE
x = np.atleast_2d(np.linspace(0,10,1000)).T # and flatten
# instantiate gauss process
gp = GaussianProcess(corr='cubic', theta0=1e-2, thetaL=1e-4,
thetaU=1e-1, random_start=100)
# fit to data using maximum likelihood estimation of params
gp.fit(X,y)
# make predictions on meshed x-axis, also return MSE
y_pred, MSE = gp.predict(x, eval_MSE=True)
sigma = np.sqrt(MSE)
# plot
fig = plt.figure()
plt.plot(x, f(x), 'r:', label=u'$f(x) = x\,\sin(x)$')
plt.plot(X, y, 'r.', markersize=10, label=u'Observations')
plt.plot(x, y_pred, 'b-', label=u'Prediction')
# fill the space between the +/-MSE
plt.fill(np.concatenate([x, x[::-1]]), # reverse order of x
np.concatenate([y_pred - 1.9600 * sigma,
(y_pred + 1.9600 * sigma)[::-1]]),
alpha=0.5, fc='b', ec='None', label='95% confidence interval')
# shade, fill color, edge color
plt.title('Noiseless case')
plt.xlabel('$x$')
plt.ylabel('$f(x)$')
plt.ylim(-10, 20)
plt.legend(loc='upper left')
return
示例10: GPVisualize1D
def GPVisualize1D(self, locations, measurements, predict_range = (0, 1), num_samples = 1000):
"""
Visualize posterior in graphical form
NOTE: very ineffecient since we are using the weight space view to vizualize this
"""
# Grid points
x = np.atleast_2d(np.linspace(predict_range[0], predict_range[1], num_samples, endpoint=False)).T
# Compute predictions - very inefficient because we are using the weight space view
predicted_mean = [0.0] * num_samples
predicted_variance = [0.0] * num_samples
for i in xrange(num_samples):
predicted_mean[i] = self.GPMean(locations, measurements, x[i])[0]
predicted_variance[i] = self.GPVariance2(locations, x[i])[0]
# Plot posterior mean and variances
pl.plot(x, self.GPRegressionTestEnvironment(x), 'r:', label=u'$f(x)$')
pl.plot(locations, measurements, 'r.', markersize=10, label=u'Observations')
pl.plot(x, predicted_mean, 'b-', label=u'Prediction')
pl.fill(np.concatenate([x, x[::-1]]),
np.concatenate([predicted_mean - 1.9600 * np.sqrt(predicted_variance),
(predicted_mean + 1.9600 * np.sqrt(predicted_variance))[::-1]]),
alpha=.5, fc='b', ec='None', label='95% confidence interval')
pl.xlabel('$x$')
pl.ylabel('$f(x)$')
pl.legend(loc='upper left')
pl.show()
示例11: hinton
def hinton(W, maxWeight=None):
"""
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if plt.isinteractive():
plt.ioff()
plt.clf()
height, width = W.shape
if not maxWeight:
maxWeight = 2**np.ceil(np.log(np.max(np.abs(W)))/np.log(2))
plt.fill(np.array([0, width, width, 0]), np.array([0, 0, height, height]),
'gray')
plt.axis('off')
plt.axis('equal')
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y, x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5,
min(1, w/maxWeight), 'white')
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5,
min(1, -w/maxWeight), 'black')
if reenable:
plt.ion()
plt.show()
示例12: main
def main():
x = linspace(0, 1, 200)
y = sin(4 * pi * x) * exp(-5 * x)
fill(x, y, 'r')
grid(True)
show()
示例13: convexview
def convexview(linearcombination):
# draw K
plt.plot([1.0, 2.0, 20.0, 3.0, 1.0],[2.0, 4.0, 0.0, 1.0, 2.0],'b',lw=2.0)
plt.fill([1.0, 2.0, 20.0, 3.0, 1.0],[2.0, 4.0, 0.0, 1.0, 2.0],
facecolor='b', alpha=0.2, edgecolor='none')
plt.text(3.5,1.2,r'$K$',fontsize=28,color='b')
# draw axes
plt.plot([0.5, 0.5],[-0.5, 4.5],'k',lw=1.0)
plt.plot([0.0, 4.0],[0.5, 0.5],'k',lw=1.0)
# plot u, v
u = np.array([1.6,1.7])
v = np.array([3.0,3.0])
plt.plot(u[0],u[1],'.',markersize=14,color='k')
plt.text(u[0]-0.3,u[1]-0.3,r'$u$',fontsize=24,color='k')
plt.plot(v[0],v[1],'.',markersize=14,color='k')
plt.text(v[0]+0.1,v[1]+0.1,r'$v$',fontsize=24,color='k')
# show either interpretation
eps = 0.6
z = (1.0 - eps) * u + eps * v
plt.plot(z[0],z[1],'.',markersize=14,color='k')
if linearcombination:
# lin-comb : (1 - eps) u + eps v
plt.plot([u[0],v[0]], [u[1],v[1]],'k',lw=2.0)
plt.text(z[0],z[1]-0.3,r'$(1-\varepsilon) u + \varepsilon v$',fontsize=24,color='k')
else:
# intoK : u + eps (v - u)
ax = plt.axes()
w = eps * (v - u)
ax.arrow(u[0],u[1],w[0],w[1],
head_width=0.1, head_length=0.2, length_includes_head=True, fc='k', ec='k')
plt.text(z[0],z[1]-0.3,r'$u + \varepsilon (v - u)$',fontsize=24,color='k')
plt.axis([-1.0,4.0,0.0,5.0],'k',lw=2.0)
plt.axis('off')
示例14: __main__
def __main__():
'''test code'''
# make up data points
#np.random.seed(1234)
points = np.random.rand(3, 2)
# compute Voronoi tesselation
vor = Voronoi(points)
# plot
regions, vertices = voronoi_finite_polygons_2d(vor,radius=100000)
print("--")
print(regions)
print("--")
print(vertices)
# colorize
for region in regions:
polygon = vertices[region]
plt.fill(*zip(*polygon), alpha=0.4)
plt.plot(points[:,0], points[:,1], 'ko')
plt.axis('equal')
plt.xlim(vor.min_bound[0] - 0.1, vor.max_bound[0] + 0.1)
plt.ylim(vor.min_bound[1] - 0.1, vor.max_bound[1] + 0.1)
#plt.savefig('voro.png')
plt.show()
示例15: test_voronoi
def test_voronoi(self):
# make up data points
np.random.seed(1234)
points = np.random.rand(15, 2)
# compute Voronoi tesselation
vor = Voronoi(points)
# plot
regions, vertices = self.voronoi_finite_polygons_2d(vor)
print "--"
print regions
print "--"
print vertices
# colorize
for region in regions:
polygon = vertices[region]
plt.fill(*zip(*polygon), alpha=0.4)
plt.plot(points[:, 0], points[:, 1], "ko")
plt.xlim(vor.min_bound[0] - 0.1, vor.max_bound[0] + 0.1)
plt.ylim(vor.min_bound[1] - 0.1, vor.max_bound[1] + 0.1)
plt.show()