本文整理汇总了Python中matplotlib.collections.PatchCollection.set_norm方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_norm方法的具体用法?Python PatchCollection.set_norm怎么用?Python PatchCollection.set_norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_norm方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
class Visualize:
def __init__(self, v, t, e, fig, win, axesLimit=[-3,3.5,-2,2]):
self.e = e.copy()
self.p = [Polygon(v[ti]) for ti in t]
self.p = PatchCollection(self.p, edgecolors='none')
self.l = LineCollection(v[e[:,:2]])
win = win or fig.canvas.manager.window
if fig is None: fig = gcf()
fig.clf()
ax = fig.add_axes([0.02,0.02,.98,.98])
ax.axis('scaled')
ax.axis(axesLimit)
ax.set_autoscale_on(False)
self.axis, self.fig, self.win = ax, fig, win
ax.add_collection(self.p)
ax.add_collection(self.l)
# ax.add_collection(self.l1)
# ax.add_collection(self.l2)
def update(self, title, phi):
norm = Normalize(phi.min(), phi.max())
self.p.set_norm(norm)
self.l.set_norm(norm)
self.p.set_array(phi)
self.l.set_array(phi[self.e[:,2:]].mean(1))
if not self.__dict__.has_key('colorbar'):
self.colorbar = self.fig.colorbar(self.p)
self.win.set_title(title)
#self.fig.canvas.set_window_title(title)
self.fig.canvas.draw()
示例2: render
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
def render(self,ax,alpha=.7,usePyLeaflet=False,
minValueThreshold=-float('Inf'),logScale=True,colormapname='BlueRed'):
if not usePyLeaflet or colormapname=='nothingRed':
alpha=1.0
patches = []
values = []
colorvalues = []
for d in self.countPerGeohash.keys():
try:
if (self.countPerGeohash[d]>minValueThreshold):
bbox = geohash.bbox(d)
rect = mpatches.Rectangle([ bbox['w'],
bbox['s']],
bbox['e'] - bbox['w'],
bbox['n'] - bbox['s'],
ec='none', lw=.1, fc='red', alpha=alpha)
patches.append(rect)
# values.append(self.countPerGeohash[d] \
# if self.countPerGeohash[d]<3 else self.countPerGeohash[d]+10)
# colorvalues.append(self.countPerGeohash[d] \
# if self.countPerGeohash[d]<3 else self.countPerGeohash[d]+10)
values.append(self.countPerGeohash[d])
colorvalues.append(self.countPerGeohash[d])
except KeyError:
print("'"+d +"' is not a valid geohash.")
try:
maxval = max(values)
minval = min(values)
except ValueError:
print('heatmap appears to be empty...')
maxval = 1
minval = 0
p = PatchCollection(patches,cmap=plt.get_cmap(colormapname),alpha=alpha)
# if usePyLeaflet:
if (len(values)<100):
p.set_edgecolors(np.array(['black' for x in values]))
else:
p.set_edgecolors(np.array(['#333333' if x<=2 \
else ('#666666' if x<=10 else 'black') for x in values]))
# else:
# p.set_edgecolors(np.array(['white' for x in values]))
p.set_array(np.array(colorvalues))
if logScale:
p.set_norm(colors.LogNorm(vmin=.01, vmax=maxval))
else:
p.set_norm(colors.Normalize(vmin=0, vmax=maxval))
ax.add_collection(p)
ax.set_xlim(self.bbox['w'], self.bbox['e'])
ax.set_ylim(self.bbox['s'], self.bbox['n'])
divider = make_axes_locatable(ax)
cbar = plt.colorbar(p)
cbar.set_clim(vmin=max(0,minval),vmax=maxval)
cbar.update_normal(p)
return
示例3: draw1DColumn
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
def draw1DColumn(ax, x, val, thk, width=30, ztopo=0, cmin=1, cmax=1000,
cmap=None, name=None, textoffset=0.0):
"""Draw a 1D column (e.g., from a 1D inversion) on a given ax.
Examples
--------
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from pygimli.mplviewer import draw1DColumn
>>> thk = [1, 2, 3, 4]
>>> val = thk
>>> fig, ax = plt.subplots()
>>> draw1DColumn(ax, 0.5, val, thk, width=0.1, cmin=1, cmax=4, name="VES")
<matplotlib.collections.PatchCollection object at ...>
>>> ax.set_ylim(-np.sum(thk), 0)
(-10, 0)
"""
z = -np.hstack((0., np.cumsum(thk), np.sum(thk) * 1.5)) + ztopo
recs = []
for i in range(len(val)):
recs.append(Rectangle((x - width / 2., z[i]), width, z[i + 1] - z[i]))
pp = PatchCollection(recs)
col = ax.add_collection(pp)
pp.set_edgecolor(None)
pp.set_linewidths(0.0)
if cmap is not None:
if isinstance(cmap, str):
pp.set_cmap(pg.mplviewer.cmapFromName(cmap))
else:
pp.set_cmap(cmap)
pp.set_norm(colors.LogNorm(cmin, cmax))
pp.set_array(np.array(val))
pp.set_clim(cmin, cmax)
if name:
ax.text(x+textoffset, ztopo, name, ha='center', va='bottom')
updateAxes_(ax)
return col
示例4: showStitchedModels
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
def showStitchedModels(mods, axes=None, cmin=None, cmax=None, **kwargs):
"""
Show several 1d block models as (stitched) section.
"""
x = kwargs.pop('x', np.arange(len(mods)))
topo = kwargs.pop('topo', x*0)
nlay = int(np.floor((len(mods[0]) - 1) / 2.)) + 1
if cmin is None or cmax is None:
cmin = 1e9
cmax = 1e-9
for model in mods:
res = np.asarray(model)[nlay - 1:nlay * 2 - 1]
cmin = min(cmin, min(res))
cmax = max(cmax, max(res))
if kwargs.pop('sameSize', True): # all having the same width
dx = np.ones_like(x)*np.median(np.diff(x))
else:
dx = np.diff(x) * 1.05
dx = np.hstack((dx, dx[-1]))
x1 = x - dx / 2
if axes is None:
fig, ax = plt.subplots()
else:
ax = axes
fig = ax.figure
# ax.plot(x, x * 0., 'k.')
zm = kwargs.pop('zm', None)
maxz = 0.
if zm is not None:
maxz = zm
recs = []
RES = []
for i, mod in enumerate(mods):
mod1 = np.asarray(mod)
res = mod1[nlay - 1:]
RES.extend(res)
thk = mod1[:nlay - 1]
thk = np.hstack((thk, thk[-1]))
z = np.hstack((0., np.cumsum(thk)))
if zm is not None:
thk[-1] = zm - z[-2]
z[-1] = zm
else:
maxz = max(maxz, z[-1])
for j in range(len(thk)):
recs.append(Rectangle((x1[i], topo[i]-z[j]), dx[i], -thk[j]))
pp = PatchCollection(recs, edgecolors=kwargs.pop('edgecolors', 'none'))
pp.set_edgecolor(kwargs.pop('edgecolors', 'none'))
pp.set_linewidths(0.0)
ax.add_collection(pp)
if 'cmap' in kwargs:
pp.set_cmap(kwargs['cmap'])
print(cmin, cmax)
norm = LogNorm(cmin, cmax)
pp.set_norm(norm)
pp.set_array(np.array(RES))
# pp.set_clim(cmin, cmax)
ax.set_ylim((-maxz, max(topo)))
ax.set_xlim((x1[0], x1[-1] + dx[-1]))
cbar = None
if kwargs.pop('colorBar', True):
cbar = plt.colorbar(pp, ax=ax, norm=norm, orientation='horizontal',
aspect=60) # , ticks=[1, 3, 10, 30, 100, 300])
if 'ticks' in kwargs:
cbar.set_ticks(kwargs['ticks'])
# cbar.autoscale_None()
if axes is None: # newly created fig+ax
return fig, ax
else: # already given, better give back color bar
return cbar
示例5: patchValMap
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
def patchValMap(vals, xvec=None, yvec=None, ax=None, cMin=None, cMax=None,
logScale=None, label=None, dx=1, dy=None, **kwargs):
""" plot previously generated (generateVecMatrix) y map (category)
Parameters
----------
A : iterable
to show
xvec : dict {i:num}
dict (must match A.shape[0])
ymap : iterable
vector for x axis (must match A.shape[0])
ax : mpl.axis
axis to plot, if not given a new figure is created
cMin/cMax : float
minimum/maximum color values
logScale : bool
logarithmic colour scale [min(A)>0]
label : string
colorbar label
"""
if cMin is None:
cMin = np.min(vals)
if cMax is None:
cMax = np.max(vals)
if logScale is None:
logScale = (cMin > 0.0)
if logScale:
norm = LogNorm(vmin=cMin, vmax=cMax)
else:
norm = Normalize(vmin=cMin, vmax=cMax)
if 'ax' is None:
fig, ax = plt.subplots()
recs = []
if dy is None: # map y values to unique
ymap = {xy: ii for ii, xy in enumerate(np.unique(yvec))}
for i in range(len(vals)):
recs.append(Rectangle((xvec[i]-dx/2, ymap[yvec[i]]-0.5), dx, 1))
else:
for i in range(len(vals)):
recs.append(Rectangle((xvec[i]-dx/2, yvec[i]-dy/2), dx, dy))
pp = PatchCollection(recs)
col = ax.add_collection(pp)
pp.set_edgecolor(None)
pp.set_linewidths(0.0)
if 'cmap' in kwargs:
pp.set_cmap(kwargs.pop('cmap'))
pp.set_norm(norm)
pp.set_array(np.array(vals))
pp.set_clim(cMin, cMax)
ax.set_xlim(min(xvec)-dx/2, max(xvec)+dx/2)
ax.set_ylim(len(ymap)-0.5, -0.5)
updateAxes_(ax)
cbar = None
if kwargs.pop('colorBar', True):
cbar = pg.mplviewer.createColorbar(col, cMin=cMin, cMax=cMax, nLevs=5,
label=label)
return ax, cbar, ymap
示例6: patchMatrix
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
def patchMatrix(A, xmap=None, ymap=None, ax=None, cMin=None, cMax=None,
logScale=None, label=None, dx=1, **kwargs):
""" plot previously generated (generateVecMatrix) matrix
Parameters
----------
A : numpy.array2d
matrix to show
xmap : dict {i:num}
dict (must match A.shape[0])
ymap : iterable
vector for x axis (must match A.shape[0])
ax : mpl.axis
axis to plot, if not given a new figure is created
cMin/cMax : float
minimum/maximum color values
logScale : bool
logarithmic colour scale [min(A)>0]
label : string
colorbar label
"""
mat = np.ma.masked_where(A == 0.0, A, False)
if cMin is None:
cMin = np.min(mat)
if cMax is None:
cMax = np.max(mat)
if logScale is None:
logScale = (cMin > 0.0)
if logScale:
norm = LogNorm(vmin=cMin, vmax=cMax)
else:
norm = Normalize(vmin=cMin, vmax=cMax)
if 'ax' is None:
fig, ax = plt.subplots()
iy, ix = np.nonzero(A) # != 0)
recs = []
vals = []
for i in range(len(ix)):
recs.append(Rectangle((ix[i]-dx/2, iy[i]-0.5), dx, 1))
vals.append(A[iy[i], ix[i]])
pp = PatchCollection(recs)
col = ax.add_collection(pp)
pp.set_edgecolor(None)
pp.set_linewidths(0.0)
if 'cmap' in kwargs:
pp.set_cmap(kwargs.pop('cmap'))
pp.set_norm(norm)
pp.set_array(np.array(vals))
pp.set_clim(cMin, cMax)
xval = [k for k in xmap.keys()]
ax.set_xlim(min(xval)-dx/2, max(xval)+dx/2)
ax.set_ylim(len(ymap)+0.5, -0.5)
updateAxes_(ax)
cbar = None
if kwargs.pop('colorBar', True):
cbar = pg.mplviewer.createColorbar(col, cMin=cMin, cMax=cMax, nLevs=5,
label=label)
return ax, cbar
示例7: patchValMap
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_norm [as 别名]
#.........这里部分代码省略.........
else:
norm = Normalize(vmin=cMin, vmax=cMax)
if ax is None:
ax = plt.subplots()[1]
recs = []
circular = kwargs.pop('circular', False)
if circular:
recs = [None] * len(xvec)
if dy is None: # map y values to unique
ymap = {xy: ii for ii, xy in enumerate(np.unique(yvec))}
xyMap = {}
for i, y in enumerate(yvec):
if y not in xyMap:
xyMap[y] = []
xyMap[y].append(i)
# maxR = max(ymap.values()) # what's that for? not used
dR = 1 / (len(ymap.values())+1)
# dOff = np.pi / 2 # what's that for? not used
for y, xIds in xyMap.items():
r = 1. - dR*(ymap[y]+1)
# ax.plot(r * np.cos(xvec[xIds]),
# r * np.sin(xvec[xIds]), 'o')
# print(y, ymap[y])
for i in xIds:
phi = xvec[i]
# x = r * np.cos(phi) # what's that for? not used
y = r * np.sin(phi)
dPhi = (xvec[1] - xvec[0])
recs[i] = Wedge((0., 0.), r + dR/1.5,
(phi - dPhi)*360/(2*np.pi),
(phi + dPhi)*360/(2*np.pi),
width=dR,
zorder=1+r)
# if i < 5:
# ax.text(x, y, str(i))
# pg.wait()
else:
raise("Implementme")
else:
if dy is None: # map y values to unique
ymap = {xy: ii for ii, xy in enumerate(np.unique(yvec))}
for i in range(len(vals)):
recs.append(Rectangle((xvec[i] - dx / 2, ymap[yvec[i]] - 0.5),
dx, 1))
else:
for i in range(len(vals)):
recs.append(Rectangle((xvec[i] - dx / 2, yvec[i] - dy / 2),
dx, dy))
ax.set_xlim(min(xvec) - dx / 2, max(xvec) + dx / 2)
ax.set_ylim(len(ymap) - 0.5, -0.5)
pp = PatchCollection(recs)
# ax.clear()
col = ax.add_collection(pp)
pp.set_edgecolor(None)
pp.set_linewidths(0.0)
if circular:
pp.set_edgecolor('black')
pp.set_linewidths(0.1)
cmap = pg.mplviewer.cmapFromName(**kwargs)
if kwargs.pop('markOutside', False):
cmap.set_bad('grey')
cmap.set_under('darkgrey')
cmap.set_over('lightgrey')
cmap.set_bad('black')
pp.set_cmap(cmap)
pp.set_norm(norm)
pp.set_array(vals)
pp.set_clim(cMin, cMax)
updateAxes_(ax)
cbar = kwargs.pop('colorBar', True)
ori = kwargs.pop('orientation', 'horizontal')
if cbar in ['horizontal', 'vertical']:
ori = cbar
cbar = True
if cbar is True: # not for cbar=1, which is really confusing!
cbar = pg.mplviewer.createColorBar(col, cMin=cMin, cMax=cMax,
nLevs=5, label=label,
orientation=ori)
elif cbar is not False:
# .. cbar is an already existing cbar .. so we update its values
pg.mplviewer.updateColorBar(cbar, cMin=cMin, cMax=cMax,
nLevs=5, label=label)
updateAxes_(ax)
return ax, cbar, ymap