本文整理匯總了Python中matplotlib.pyplot.clabel方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.clabel方法的具體用法?Python pyplot.clabel怎麽用?Python pyplot.clabel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.clabel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_collection
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_collection():
x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100))
data = np.sin(x) + np.cos(y)
cs = plt.contour(data)
pe = [path_effects.PathPatchEffect(edgecolor='black', facecolor='none',
linewidth=12),
path_effects.Stroke(linewidth=5)]
for collection in cs.collections:
collection.set_path_effects(pe)
for text in plt.clabel(cs, colors='white'):
text.set_path_effects([path_effects.withStroke(foreground='k',
linewidth=3)])
text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none',
'edgecolor': 'blue'})
示例2: visualizeFit
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def visualizeFit(X,mu,sigma2):
x = np.arange(0, 36, 0.5) # 0-36,步長0.5
y = np.arange(0, 36, 0.5)
X1,X2 = np.meshgrid(x,y) # 要畫等高線,所以meshgird
Z = multivariateGaussian(np.hstack((X1.reshape(-1,1),X2.reshape(-1,1))), mu, sigma2) # 計算對應的高斯分布函數
Z = Z.reshape(X1.shape) # 調整形狀
plt.plot(X[:,0],X[:,1],'bx')
if np.sum(np.isinf(Z).astype(float)) == 0: # 如果計算的為無窮,就不用畫了
#plt.contourf(X1,X2,Z,10.**np.arange(-20, 0, 3),linewidth=.5)
CS = plt.contour(X1,X2,Z,10.**np.arange(-20, 0, 3),color='black',linewidth=.5) # 畫等高線,Z的值在10.**np.arange(-20, 0, 3)
#plt.clabel(CS)
plt.show()
# 選擇最優的epsilon,即:使F1Score最大
示例3: test_labels
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_labels():
# Adapted from pylab_examples example code: contour_demo.py
# see issues #2475, #2843, and #2818 for explanation
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
fig, ax = plt.subplots(1, 1)
CS = ax.contour(X, Y, Z)
disp_units = [(216, 177), (359, 290), (521, 406)]
data_units = [(-2, .5), (0, -1.5), (2.8, 1)]
CS.clabel()
for x, y in data_units:
CS.add_label_near(x, y, inline=True, transform=None)
for x, y in disp_units:
CS.add_label_near(x, y, inline=True, transform=False)
示例4: Pcolor
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def Pcolor(xs, ys, zs, pcolor=True, contour=False, **options):
"""Makes a pseudocolor plot.
xs:
ys:
zs:
pcolor: boolean, whether to make a pseudocolor plot
contour: boolean, whether to make a contour plot
options: keyword args passed to plt.pcolor and/or plt.contour
"""
_Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)
X, Y = np.meshgrid(xs, ys)
Z = zs
x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
axes = plt.gca()
axes.xaxis.set_major_formatter(x_formatter)
if pcolor:
plt.pcolormesh(X, Y, Z, **options)
if contour:
cs = plt.contour(X, Y, Z, **options)
plt.clabel(cs, inline=1, fontsize=10)
示例5: test_contour_badlevel_fmt
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_contour_badlevel_fmt():
# test funny edge case from
# https://github.com/matplotlib/matplotlib/issues/9742
# User supplied fmt for each level as a dictionary, but
# MPL changed the level to the minimum data value because
# no contours possible.
# This would error out pre
# https://github.com/matplotlib/matplotlib/pull/9743
x = np.arange(9)
z = np.zeros((9, 9))
fig, ax = plt.subplots()
fmt = {1.: '%1.2f'}
with pytest.warns(UserWarning) as record:
cs = ax.contour(x, x, z, levels=[1.])
ax.clabel(cs, fmt=fmt)
assert len(record) == 1
示例6: Pcolor
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def Pcolor(xs, ys, zs, pcolor=True, contour=False, **options):
"""Makes a pseudocolor plot.
xs:
ys:
zs:
pcolor: boolean, whether to make a pseudocolor plot
contour: boolean, whether to make a contour plot
options: keyword args passed to pyplot.pcolor and/or pyplot.contour
"""
_Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)
X, Y = np.meshgrid(xs, ys)
Z = zs
x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
axes = pyplot.gca()
axes.xaxis.set_major_formatter(x_formatter)
if pcolor:
pyplot.pcolormesh(X, Y, Z, **options)
if contour:
cs = pyplot.contour(X, Y, Z, **options)
pyplot.clabel(cs, inline=1, fontsize=10)
示例7: test_patheffect2
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_patheffect2():
ax2 = plt.subplot(111)
arr = np.arange(25).reshape((5, 5))
ax2.imshow(arr)
cntr = ax2.contour(arr, colors="k")
plt.setp(cntr.collections,
path_effects=[path_effects.withStroke(linewidth=3,
foreground="w")])
clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
plt.setp(clbls,
path_effects=[path_effects.withStroke(linewidth=3,
foreground="w")])
示例8: test_contour_labels_size_color
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_contour_labels_size_color():
x, y = np.meshgrid(np.arange(0, 10), np.arange(0, 10))
z = np.max(np.dstack([abs(x), abs(y)]), 2)
plt.figure(figsize=(6, 2))
cs = plt.contour(x, y, z)
pts = np.array([(1.5, 3.0), (1.5, 4.4), (1.5, 6.0)])
plt.clabel(cs, manual=pts, fontsize='small', colors=('r', 'g'))
示例9: test_circular_contour_warning
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_circular_contour_warning():
# Check that almost circular contours don't throw a warning
with pytest.warns(None) as record:
x, y = np.meshgrid(np.linspace(-2, 2, 4), np.linspace(-2, 2, 4))
r = np.sqrt(x ** 2 + y ** 2)
plt.figure()
cs = plt.contour(x, y, r)
plt.clabel(cs)
assert len(record) == 0
示例10: DrawContourAndMark
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def DrawContourAndMark(contour, x, y, z, level, clipborder, patch, m):
# 是否繪製等值線 ------ 等值線和標注是一體的
if contour.contour['visible']:
matplotlib.rcParams['contour.negative_linestyle'] = 'dashed'
if contour.contour['colorline']:
CS1 = m.contour(x, y, z, levels=level, linewidths=contour.contour['linewidth'])
else:
CS1 = m.contour(x,
y,
z,
levels=level,
linewidths=contour.contour['linewidth'],
colors=contour.contour['linecolor'])
# 是否繪製等值線標注
CS2 = None
if contour.contourlabel['visible']:
CS2 = plt.clabel(CS1,
inline=1,
fmt=contour.contourlabel['fmt'],
inline_spacing=contour.contourlabel['inlinespacing'],
fontsize=contour.contourlabel['fontsize'],
colors=contour.contourlabel['fontcolor'])
# 用區域邊界裁切等值線圖
if clipborder.path is not None and clipborder.using:
for collection in CS1.collections:
# collection.set_clip_on(True)
collection.set_clip_path(patch)
if CS2 is not None:
for text in CS2:
if not clipborder.path.contains_point(text.get_position()):
text.remove()
示例11: test_contour_manual_labels
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_contour_manual_labels():
x, y = np.meshgrid(np.arange(0, 10), np.arange(0, 10))
z = np.max(np.dstack([abs(x), abs(y)]), 2)
plt.figure(figsize=(6, 2))
cs = plt.contour(x, y, z)
pts = np.array([(1.5, 3.0), (1.5, 4.4), (1.5, 6.0)])
plt.clabel(cs, manual=pts)
示例12: Contour
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def Contour(obj, pcolor=False, contour=True, imshow=False, **options):
"""Makes a contour plot.
d: map from (x, y) to z, or object that provides GetDict
pcolor: boolean, whether to make a pseudocolor plot
contour: boolean, whether to make a contour plot
imshow: boolean, whether to use plt.imshow
options: keyword args passed to plt.pcolor and/or plt.contour
"""
try:
d = obj.GetDict()
except AttributeError:
d = obj
_Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)
xs, ys = zip(*d.keys())
xs = sorted(set(xs))
ys = sorted(set(ys))
X, Y = np.meshgrid(xs, ys)
func = lambda x, y: d.get((x, y), 0)
func = np.vectorize(func)
Z = func(X, Y)
x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
axes = plt.gca()
axes.xaxis.set_major_formatter(x_formatter)
if pcolor:
plt.pcolormesh(X, Y, Z, **options)
if contour:
cs = plt.contour(X, Y, Z, **options)
plt.clabel(cs, inline=1, fontsize=10)
if imshow:
extent = xs[0], xs[-1], ys[0], ys[-1]
plt.imshow(Z, extent=extent, **options)
示例13: test_contour_manual_labels
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def test_contour_manual_labels():
x, y = np.meshgrid(np.arange(0, 10), np.arange(0, 10))
z = np.max(np.dstack([abs(x), abs(y)]), 2)
plt.figure(figsize=(6, 2), dpi=200)
cs = plt.contour(x, y, z)
pts = np.array([(1.5, 3.0), (1.5, 4.4), (1.5, 6.0)])
plt.clabel(cs, manual=pts)
示例14: visualize_function
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def visualize_function(self, func, show_3d=True, show_3d_inv=True,
show_contour=True, num_levels=15, rng_x=(-5, 5),
rng_y=(-5, 5)):
import matplotlib.pyplot as plt
if self._dim == 1:
xs = np.linspace(rng_x[0], rng_x[1], 100)
plt.plot(xs, np.apply_along_axis(func, 0, xs[np.newaxis, :]))
elif self._dim == 2:
freq = 50
x = np.linspace(rng_x[0], rng_x[1], freq)
y = np.linspace(rng_y[0], rng_y[1], freq)
Xs, Ys = np.meshgrid(x, y)
xs = np.reshape(Xs, -1)
ys = np.reshape(Ys, -1)
zs = np.apply_along_axis(func, 0, np.vstack((xs, ys)))
if show_3d:
fig = plt.figure(figsize=(10, 10))
ax = fig.gca(projection='3d')
ax.plot_trisurf(xs, ys, zs, linewidth=0.2, antialiased=True)
plt.show()
if show_3d_inv:
fig = plt.figure(figsize=(10, 10))
ax = fig.gca(projection='3d')
ax.invert_zaxis()
ax.plot_trisurf(xs, ys, zs, linewidth=0.2, antialiased=True)
plt.show()
if show_contour:
fig = plt.figure(figsize=(10, 10))
cs = plt.contour(Xs, Ys, zs.reshape(freq, freq), num_levels)
plt.clabel(cs, inline=1, fontsize=10)
plt.show()
else:
raise ValueError("Only dim=1 or dim=2 are supported")
示例15: visualize_distribution
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import clabel [as 別名]
def visualize_distribution(log_densities, ax = None):
if ax is None:
ax = plt.gca()
t = normalize_log_density(log_densities)
img = ax.imshow(t, cmap=plt.cm.viridis)
levels = levels=[0, 0.25, 0.5, 0.75, 1.0]
cs = ax.contour(t, levels=levels, colors='black')
#plt.clabel(cs)
return img, cs