本文整理汇总了Python中matplotlib.pyplot.pcolor方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.pcolor方法的具体用法?Python pyplot.pcolor怎么用?Python pyplot.pcolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.pcolor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cmap_import
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_cmap_import():
'''Can we import colormaps and make basic plot.
'''
from cmocean import cm
# Loop through all methods in cmocean.
for name, cmap in vars(cm).items():
# See if it is a colormap.
if isinstance(cmap, matplotlib.colors.LinearSegmentedColormap):
print(name)
x = np.linspace(0, 10)
X, _ = np.meshgrid(x, x)
plt.figure()
plt.pcolor(X, cmap=cmap)
plt.title(name)
plt.close(plt.gcf())
示例2: test_pcolor_datetime_axis
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_pcolor_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(21)])
y = np.arange(21)
z1, z2 = np.meshgrid(np.arange(20), np.arange(20))
z = z1 * z2
plt.subplot(221)
plt.pcolor(x[:-1], y[:-1], z)
plt.subplot(222)
plt.pcolor(x, y, z)
x = np.repeat(x[np.newaxis], 21, axis=0)
y = np.repeat(y[:, np.newaxis], 21, axis=1)
plt.subplot(223)
plt.pcolor(x[:-1, :-1], y[:-1, :-1], z)
plt.subplot(224)
plt.pcolor(x, y, z)
for ax in fig.get_axes():
for label in ax.get_xticklabels():
label.set_ha('right')
label.set_rotation(30)
示例3: Pcolor
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [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)
示例4: plot_colormap
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def plot_colormap(data, figSizeIn, xlabel, ylabel, cbarlabel, cmapIn, ytickRange, ytickTag, xtickRange=None, xtickTag=None, title=None):
fig = plt.figure(figsize = figSizeIn)
plt.pcolor(data, cmap=cmapIn)
cbar = plt.colorbar()
cbar.set_label(cbarlabel, labelpad=-0.1)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
if xtickTag:
plt.xticks(xtickRange, xtickTag, fontsize=10)
plt.yticks(ytickRange, ytickTag, fontsize=10)
plt.tight_layout()
if title:
plt.title(title)
plt.show()
return fig
示例5: plot_colormap_upgrade
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def plot_colormap_upgrade(data, figSizeIn, xlabel, ylabel, cbarlabel, cmapIn, ytickRange, ytickTag, xtickRange=None, xtickTag=None, title=None, xmin=None, xmax=None, xgran=None, ymin=None, ymax=None, ygran=None):
if xmin != None:
y, x = np.mgrid[slice(ymin, ymax + ygran, ygran),
slice(xmin, xmax + xgran, xgran)]
fig = plt.figure(figsize = figSizeIn)
# plt.pcolor(data, cmap=cmapIn)
plt.pcolormesh(x, y, data, cmap=cmapIn)
plt.grid(which='major',axis='both')
plt.axis([x.min(), x.max(), y.min(), y.max()])
else:
plt.pcolor(data, cmap=cmapIn)
cbar = plt.colorbar()
cbar.set_label(cbarlabel, labelpad=-0.1)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
# if xtickTag:
# plt.xticks(xtickRange, xtickTag, fontsize=10)
#
# plt.yticks(ytickRange, ytickTag, fontsize=10)
plt.tight_layout()
if title:
plt.title(title)
plt.show()
return fig
示例6: draw_pianoroll
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def draw_pianoroll(pianoroll, name='Notes', show=False, save_path=''):
cm = matplotlib.cm.get_cmap('Greys')
notes_color = cm(1.0)
notes_patch = mpatches.Patch(color=notes_color, label=name)
plt.figure(figsize=(20.0, 10.0))
plt.title('Pianoroll Pitch-plot of ' + name, fontsize=10)
plt.legend(handles=[notes_patch], loc='upper right', prop={'size': 8})
plt.pcolor(pianoroll, cmap='Greys', vmin=0, vmax=np.max(pianoroll))
if show:
plt.show()
if len(save_path) > 0:
plt.savefig(save_path)
tikz_save(save_path + ".tex", encoding='utf-8', show_info=False)
plt.close()
示例7: Pcolor
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [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)
示例8: plot_solution
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def plot_solution(X_star, u_star, index):
lb = X_star.min(0)
ub = X_star.max(0)
nn = 200
x = np.linspace(lb[0], ub[0], nn)
y = np.linspace(lb[1], ub[1], nn)
X, Y = np.meshgrid(x,y)
U_star = griddata(X_star, u_star.flatten(), (X, Y), method='cubic')
plt.figure(index)
plt.pcolor(X,Y,U_star, cmap = 'jet')
plt.colorbar()
示例9: plot_solution
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def plot_solution(X_data, w_data, index):
lb = X_data.min(0)
ub = X_data.max(0)
nn = 200
x = np.linspace(lb[0], ub[0], nn)
y = np.linspace(lb[1], ub[1], nn)
X, Y = np.meshgrid(x,y)
W_data = griddata(X_data, w_data.flatten(), (X, Y), method='cubic')
plt.figure(index)
plt.pcolor(X,Y,W_data, cmap = 'jet')
plt.colorbar()
示例10: test_mixedmode
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_mixedmode():
if not check_for('xelatex'):
raise SkipTest('xelatex + pgf is required')
rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)
Y, X = np.ogrid[-1:1:40j, -1:1:40j]
plt.figure()
plt.pcolor(X**2 + Y**2).set_rasterized(True)
compare_figure('pgf_mixedmode.pdf')
# test bbox_inches clipping
示例11: test_autoscale_masked
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_autoscale_masked():
# Test for #2336. Previously fully masked data would trigger a ValueError.
data = np.ma.masked_all((12, 20))
plt.pcolor(data)
plt.draw()
示例12: Contour
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [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_pcolorargs_5205
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_pcolorargs_5205():
# Smoketest to catch issue found in gh:5205
x = [-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5]
y = [-1.5, -1.25, -1.0, -0.75, -0.5, -0.25, 0,
0.25, 0.5, 0.75, 1.0, 1.25, 1.5]
X, Y = np.meshgrid(x, y)
Z = np.hypot(X, Y)
plt.pcolor(Z)
plt.pcolor(list(Z))
plt.pcolor(x, y, Z)
plt.pcolor(X, Y, list(Z))
示例14: test_axes_margins
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_axes_margins():
fig, ax = plt.subplots()
ax.plot([0, 1, 2, 3])
assert ax.get_ybound()[0] != 0
fig, ax = plt.subplots()
ax.bar([0, 1, 2, 3], [1, 1, 1, 1])
assert ax.get_ybound()[0] == 0
fig, ax = plt.subplots()
ax.barh([0, 1, 2, 3], [1, 1, 1, 1])
assert ax.get_xbound()[0] == 0
fig, ax = plt.subplots()
ax.pcolor(np.zeros((10, 10)))
assert ax.get_xbound() == (0, 10)
assert ax.get_ybound() == (0, 10)
fig, ax = plt.subplots()
ax.pcolorfast(np.zeros((10, 10)))
assert ax.get_xbound() == (0, 10)
assert ax.get_ybound() == (0, 10)
fig, ax = plt.subplots()
ax.hist(np.arange(10))
assert ax.get_ybound()[0] == 0
fig, ax = plt.subplots()
ax.imshow(np.zeros((10, 10)))
assert ax.get_xbound() == (-0.5, 9.5)
assert ax.get_ybound() == (-0.5, 9.5)
示例15: test_mixedmode
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import pcolor [as 别名]
def test_mixedmode():
rc_xelatex = {'font.family': 'serif',
'pgf.rcfonts': False}
mpl.rcParams.update(rc_xelatex)
Y, X = np.ogrid[-1:1:40j, -1:1:40j]
plt.figure()
plt.pcolor(X**2 + Y**2).set_rasterized(True)
# test bbox_inches clipping