本文整理汇总了Python中matplotlib.pyplot.contour方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.contour方法的具体用法?Python pyplot.contour怎么用?Python pyplot.contour使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.contour方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_da
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def show_da(out_da, x_array, y_array, title=""):
nx = len(x_array)
ny = len(y_array)
out_da = out_da.reshape(ny,nx)
xmin, xmax, ymin, ymax = np.min(x_array), np.max(x_array), np.min(y_array), np.max(y_array)
extent = xmin, xmax, ymin, ymax
plt.figure(figsize=(10, 7))
fig1 = plt.contour(out_da, linewidths=2,extent = extent)#, colors = 'r')
plt.grid(True)
plt.title(title)
plt.xlabel("X, m")
plt.ylabel("Y, m")
cb = plt.colorbar()
cb.set_label('Nturns')
plt.show()
示例2: Cont
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def Cont(imG):
#This is meant to create plots similar to the ones from
#https://www.bu.edu/blazars/VLBA_GLAST/3c454.html
#for the visual comparison
import matplotlib.pyplot as plt
plt.figure()
Z = np.reshape(imG.imvec,(imG.xdim,imG.ydim))
pov = imG.xdim*imG.psize
pov_mas = pov/(RADPERUAS*1.e3)
Zmax = np.amax(Z)
print(Zmax)
levels = np.array((-0.00125*Zmax,0.00125*Zmax,0.0025*Zmax, 0.005*Zmax, 0.01*Zmax,
0.02*Zmax, 0.04*Zmax, 0.08*Zmax, 0.16*Zmax, 0.32*Zmax, 0.64*Zmax))
CS = plt.contour(Z, levels,
origin='lower',
linewidths=2,
extent=(-pov_mas/2., pov_mas/2., -pov_mas/2., pov_mas/2.))
plt.show()
示例3: plot_decisionBoundary
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def plot_decisionBoundary(X, y, model, class_='linear'):
plt = plot_data(X, y)
# 线性边界
if class_ == 'linear':
w = model.coef_
b = model.intercept_
xp = np.linspace(np.min(X[:, 0]), np.max(X[:, 0]), 100)
yp = -(w[0, 0] * xp + b) / w[0, 1]
plt.plot(xp, yp, 'b-', linewidth=2.0)
plt.show()
else: # 非线性边界
x_1 = np.transpose(np.linspace(np.min(X[:, 0]), np.max(X[:, 0]), 100).reshape(1, -1))
x_2 = np.transpose(np.linspace(np.min(X[:, 1]), np.max(X[:, 1]), 100).reshape(1, -1))
X1, X2 = np.meshgrid(x_1, x_2)
vals = np.zeros(X1.shape)
for i in range(X1.shape[1]):
this_X = np.hstack((X1[:, i].reshape(-1, 1), X2[:, i].reshape(-1, 1)))
vals[:, i] = model.predict(this_X)
plt.contour(X1, X2, vals, [0, 1], color='blue')
plt.show()
示例4: visualizeFit
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [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最大
示例5: test_collection
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [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'})
示例6: test_contour_shape_mismatch_3
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def test_contour_shape_mismatch_3():
x = np.arange(10)
y = np.arange(10)
xg, yg = np.meshgrid(x, y)
z = np.random.random((9, 10))
fig = plt.figure()
ax = fig.add_subplot(111)
try:
ax.contour(xg, y, z)
except TypeError as exc:
assert exc.args[0] == 'Number of dimensions of x and y should match.'
try:
ax.contour(x, yg, z)
except TypeError as exc:
assert exc.args[0] == 'Number of dimensions of x and y should match.'
示例7: test_contour_shape_mismatch_4
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def test_contour_shape_mismatch_4():
g = np.random.random((9, 10))
b = np.random.random((9, 9))
z = np.random.random((9, 10))
fig = plt.figure()
ax = fig.add_subplot(111)
try:
ax.contour(b, g, z)
except TypeError as exc:
print(exc.args[0])
assert re.match(
r'Shape of x does not match that of z: ' +
r'found \(9L?, 9L?\) instead of \(9L?, 10L?\)\.',
exc.args[0]) is not None
try:
ax.contour(g, b, z)
except TypeError as exc:
assert re.match(
r'Shape of y does not match that of z: ' +
r'found \(9L?, 9L?\) instead of \(9L?, 10L?\)\.',
exc.args[0]) is not None
示例8: test_given_colors_levels_and_extends
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def test_given_colors_levels_and_extends():
_, axes = plt.subplots(2, 4)
data = np.arange(12).reshape(3, 4)
colors = ['red', 'yellow', 'pink', 'blue', 'black']
levels = [2, 4, 8, 10]
for i, ax in enumerate(axes.flatten()):
plt.sca(ax)
filled = i % 2 == 0.
extend = ['neither', 'min', 'max', 'both'][i // 2]
if filled:
last_color = -1 if extend in ['min', 'max'] else None
plt.contourf(data, colors=colors[:last_color], levels=levels,
extend=extend)
else:
last_level = -1 if extend == 'both' else None
plt.contour(data, colors=colors, levels=levels[:last_level],
extend=extend)
plt.colorbar()
示例9: test_contour_datetime_axis
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def test_contour_datetime_axis():
fig = plt.figure()
fig.subplots_adjust(hspace=0.4, top=0.98, bottom=.15)
base = datetime.datetime(2013, 1, 1)
x = np.array([base + datetime.timedelta(days=d) for d in range(20)])
y = np.arange(20)
z1, z2 = np.meshgrid(np.arange(20), np.arange(20))
z = z1 * z2
plt.subplot(221)
plt.contour(x, y, z)
plt.subplot(222)
plt.contourf(x, y, z)
x = np.repeat(x[np.newaxis], 20, axis=0)
y = np.repeat(y[:, np.newaxis], 20, axis=1)
plt.subplot(223)
plt.contour(x, y, z)
plt.subplot(224)
plt.contourf(x, y, z)
for ax in fig.get_axes():
for label in ax.get_xticklabels():
label.set_ha('right')
label.set_rotation(30)
示例10: test_labels
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [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)
示例11: Pcolor
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [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)
示例12: test_contour_shape_mismatch_3
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def test_contour_shape_mismatch_3():
x = np.arange(10)
y = np.arange(10)
xg, yg = np.meshgrid(x, y)
z = np.random.random((9, 10))
fig, ax = plt.subplots()
with pytest.raises(TypeError) as excinfo:
ax.contour(xg, y, z)
excinfo.match(r'Number of dimensions of x and y should match.')
with pytest.raises(TypeError) as excinfo:
ax.contour(x, yg, z)
excinfo.match(r'Number of dimensions of x and y should match.')
示例13: test_contour_shape_mismatch_4
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def test_contour_shape_mismatch_4():
g = np.random.random((9, 10))
b = np.random.random((9, 9))
z = np.random.random((9, 10))
fig, ax = plt.subplots()
with pytest.raises(TypeError) as excinfo:
ax.contour(b, g, z)
excinfo.match(r'Shape of x does not match that of z: found \(9L?, 9L?\) ' +
r'instead of \(9L?, 10L?\)')
with pytest.raises(TypeError) as excinfo:
ax.contour(g, b, z)
excinfo.match(r'Shape of y does not match that of z: found \(9L?, 9L?\) ' +
r'instead of \(9L?, 10L?\)')
示例14: test_contour_badlevel_fmt
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [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
示例15: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contour [as 别名]
def plot(self, zmin=-1.5, zmax=1.5, step=0.25, linewidth=1, linestyle=':'):
"""Plots the field magnitude."""
if linewidth is None:
linewidth = matplotlib.rcParams['lines.linewidth']
x, y = meshgrid(
linspace(XMIN/ZOOM+XOFFSET, XMAX/ZOOM+XOFFSET, 200),
linspace(YMIN/ZOOM, YMAX/ZOOM, 200))
z = zeros_like(x)
for i in range(x.shape[0]):
for j in range(x.shape[1]):
# pylint: disable=unsupported-assignment-operation
z[i, j] = self.magnitude([x[i, j], y[i, j]])
# levels = arange(nmin, nmax+0.2, 0.2)
# cmap = pyplot.cm.get_cmap('plasma')
pyplot.contour(x, y, z, numpy.arange(zmin, zmax+step, step),
linewidths=linewidth, linestyles=linestyle, colors='k')
# pylint: disable=too-few-public-methods