本文整理汇总了Python中matplotlib.colors.Normalize方法的典型用法代码示例。如果您正苦于以下问题:Python colors.Normalize方法的具体用法?Python colors.Normalize怎么用?Python colors.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colors
的用法示例。
在下文中一共展示了colors.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def update(self, xPhys, u, title=None):
"""Plot to screen"""
self.im.set_array(-xPhys.reshape((self.nelx, self.nely)).T)
stress = self.stress_calculator.calculate_stress(xPhys, u, self.nu)
# self.stress_calculator.calculate_fdiff_stress(xPhys, u, self.nu)
self.myColorMap.set_norm(colors.Normalize(vmin=0, vmax=max(stress)))
stress_rgba = self.myColorMap.to_rgba(stress)
stress_rgba[:, :, 3] = xPhys.reshape(-1, 1)
self.stress_im.set_array(np.swapaxes(
stress_rgba.reshape((self.nelx, self.nely, 4)), 0, 1))
self.fig.canvas.draw()
self.fig.canvas.flush_events()
if title is not None:
plt.title(title)
else:
plt.xlabel("Max stress = {:.2f}".format(max(stress)[0]))
plt.pause(0.01)
示例2: make_coherence_cmap
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def make_coherence_cmap(
mapname="inferno", vmin=1e-5, vmax=1, ncolors=64, outname="coherence-cog.cpt"
):
"""Write default colormap (coherence-cog.cpt) for isce coherence images.
Parameters
----------
mapname : str
matplotlib colormap name
vmin : float
data value mapped to lower end of colormap
vmax : float
data value mapped to upper end of colormap
ncolors : int
number of discrete mapped values between vmin and vmax
"""
cmap = plt.get_cmap(mapname)
cNorm = colors.Normalize(vmin=vmin, vmax=vmax)
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cmap)
vals = np.linspace(vmin, vmax, ncolors, endpoint=True)
write_cmap(outname, vals, scalarMap)
return outname
示例3: _shade_colors
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def _shade_colors(self, color, normals):
'''
Shade *color* using normal vectors given by *normals*.
*color* can also be an array of the same length as *normals*.
'''
shade = np.array([np.dot(n / proj3d.mod(n), [-1, -1, 0.5])
for n in normals])
mask = ~np.isnan(shade)
if len(shade[mask]) > 0:
norm = Normalize(min(shade[mask]), max(shade[mask]))
color = colorConverter.to_rgba_array(color)
# shape of color should be (M, 4) (where M is number of faces)
# shape of shade should be (M,)
# colors should have final shape of (M, 4)
alpha = color[:, 3]
colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
colors[:, 3] = alpha
else:
colors = np.asanyarray(color).copy()
return colors
示例4: graph_colors
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def graph_colors(nx_graph, vmin=0, vmax=7):
cnorm = mcol.Normalize(vmin=vmin, vmax=vmax)
cpick = cm.ScalarMappable(norm=cnorm, cmap='viridis')
cpick.set_array([])
val_map = {}
for k, v in nx.get_node_attributes(nx_graph, 'attr_name').items():
val_map[k] = cpick.to_rgba(v)
colors = []
for node in nx_graph.nodes():
colors.append(val_map[node])
return colors
##############################################################################
# Generate data
# -------------
#%% circular dataset
# We build a dataset of noisy circular graphs.
# Noise is added on the structures by random connections and on the features by gaussian noise.
示例5: flow_legend
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def flow_legend():
"""
show quiver plot to indicate how arrows are colored in the flow() method.
https://stackoverflow.com/questions/40026718/different-colours-for-arrows-in-quiver-plot
"""
ph = np.linspace(0, 2*np.pi, 13)
x = np.cos(ph)
y = np.sin(ph)
u = np.cos(ph)
v = np.sin(ph)
colors = np.arctan2(u, v)
norm = Normalize()
norm.autoscale(colors)
# we need to normalize our colors array to match it colormap domain
# which is [0, 1]
colormap = cm.winter
plt.figure(figsize=(6, 6))
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.quiver(x, y, u, v, color=colormap(norm(colors)), angles='xy', scale_units='xy', scale=1)
plt.show()
示例6: _shade_colors
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def _shade_colors(self, color, normals):
'''
Shade *color* using normal vectors given by *normals*.
*color* can also be an array of the same length as *normals*.
'''
shade = np.array([np.dot(n / proj3d.mod(n), [-1, -1, 0.5])
if proj3d.mod(n) else np.nan
for n in normals])
mask = ~np.isnan(shade)
if len(shade[mask]) > 0:
norm = Normalize(min(shade[mask]), max(shade[mask]))
shade[~mask] = min(shade[mask])
color = mcolors.to_rgba_array(color)
# shape of color should be (M, 4) (where M is number of faces)
# shape of shade should be (M,)
# colors should have final shape of (M, 4)
alpha = color[:, 3]
colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
colors[:, 3] = alpha
else:
colors = np.asanyarray(color).copy()
return colors
示例7: update_likely_plot
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def update_likely_plot(self,ax):
lik = self.likelihood.cpu().detach().numpy()
# if lik.min() == lik.max():
# lik *= 0
# lik -= lik.min()
# lik /= lik.max()
lik, side = square_clock(lik, self.grid_dirs)
# lik=self.circular_placement(lik, self.grid_dirs)
# lik = lik.reshape(self.grid_rows*self.grid_dirs,self.grid_cols)
# lik = np.swapaxes(lik,0,1)
# lik = lik.reshape(self.grid_rows, self.grid_dirs*self.grid_cols)
# lik = np.concatenate((lik[0,:,:],lik[1,:,:],lik[2,:,:],lik[3,:,:]), axis=1)
if self.obj_lik == None:
self.obj_lik = ax.imshow(lik,interpolation='nearest')
ax.grid()
ticks = np.linspace(0,self.grid_rows*side, side,endpoint=False)-0.5
ax.set_yticks(ticks)
ax.set_xticks(ticks)
ax.tick_params(axis='y', labelleft='off')
ax.tick_params(axis='x', labelbottom='off')
ax.tick_params(bottom="off", left="off")
ax.set_title('Likelihood from NN')
else:
self.obj_lik.set_data(lik)
self.obj_lik.set_norm(norm = cm.Normalize().autoscale(lik))
示例8: update_gtl_plot
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def update_gtl_plot(self,ax):
# gtl = self.gt_likelihood.cpu().detach().numpy()
gtl = self.gt_likelihood
gtl, side = square_clock(gtl, self.grid_dirs)
if self.obj_gtl == None:
self.obj_gtl = ax.imshow(gtl,interpolation='nearest')
ax.grid()
ticks = np.linspace(0,self.grid_rows*side, side,endpoint=False)-0.5
ax.set_yticks(ticks)
ax.set_xticks(ticks)
ax.tick_params(axis='y', labelleft='off')
ax.tick_params(axis='x', labelbottom='off')
ax.tick_params(bottom="off", left="off")
ax.set_title('Target Likelihood')
else:
self.obj_gtl.set_data(gtl)
self.obj_gtl.set_norm(norm = cm.Normalize().autoscale(gtl))
示例9: update_likely_plot
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def update_likely_plot(self,ax):
lik = self.likelihood.cpu().detach().numpy()
# if lik.min() == lik.max():
# lik *= 0
# lik -= lik.min()
# lik /= lik.max()
lik, side = self.square_clock(lik, self.grid_dirs)
# lik=self.circular_placement(lik, self.grid_dirs)
# lik = lik.reshape(self.grid_rows*self.grid_dirs,self.grid_cols)
# lik = np.swapaxes(lik,0,1)
# lik = lik.reshape(self.grid_rows, self.grid_dirs*self.grid_cols)
# lik = np.concatenate((lik[0,:,:],lik[1,:,:],lik[2,:,:],lik[3,:,:]), axis=1)
if self.obj_lik == None:
self.obj_lik = ax.imshow(lik,interpolation='nearest')
ax.grid()
ticks = np.linspace(0,self.grid_rows*side, side,endpoint=False)-0.5
ax.set_yticks(ticks)
ax.set_xticks(ticks)
ax.tick_params(axis='y', labelleft='off')
ax.tick_params(axis='x', labelbottom='off')
ax.tick_params(bottom="off", left="off")
ax.set_title('Likelihood from NN')
else:
self.obj_lik.set_data(lik)
self.obj_lik.set_norm(norm = cm.Normalize().autoscale(lik))
示例10: update_prior_plot
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def update_prior_plot(self,ax):
bel = np.copy(self.prior)
bel,side = self.square_clock(bel, self.grid_dirs)
if self.obj_bel_prior == None:
self.obj_bel_prior = ax.imshow(bel,interpolation='nearest')
ax.grid()
ticks = np.linspace(0,self.grid_rows*side, side,endpoint=False)-0.5
ax.set_yticks(ticks)
ax.set_xticks(ticks)
ax.tick_params(axis='y', labelleft='off')
ax.tick_params(axis='x', labelbottom='off')
ax.tick_params(bottom="off", left="off")
ax.set_title('Prior (%.3f)'%self.prior.max())
else:
self.obj_bel_prior.set_data(bel)
ax.set_title('Prior (%.3f)'%self.prior.max())
self.obj_bel_prior.set_norm(norm = cm.Normalize().autoscale(bel))
示例11: update_gtl_plot
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def update_gtl_plot(self,ax):
# gtl = self.gt_likelihood.cpu().detach().numpy()
gtl = self.gt_likelihood
gtl, side = self.square_clock(gtl, self.grid_dirs)
if self.obj_gtl == None:
self.obj_gtl = ax.imshow(gtl,interpolation='nearest')
ax.grid()
ticks = np.linspace(0,self.grid_rows*side, side,endpoint=False)-0.5
ax.set_yticks(ticks)
ax.set_xticks(ticks)
ax.tick_params(axis='y', labelleft='off')
ax.tick_params(axis='x', labelbottom='off')
ax.tick_params(bottom="off", left="off")
ax.set_title('Target Likelihood')
else:
self.obj_gtl.set_data(gtl)
self.obj_gtl.set_norm(norm = cm.Normalize().autoscale(gtl))
示例12: test_Normalize
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def test_Normalize():
norm = mcolors.Normalize()
vals = np.arange(-10, 10, 1, dtype=float)
_inverse_tester(norm, vals)
_scalar_tester(norm, vals)
_mask_tester(norm, vals)
# Handle integer input correctly (don't overflow when computing max-min,
# i.e. 127-(-128) here).
vals = np.array([-128, 127], dtype=np.int8)
norm = mcolors.Normalize(vals.min(), vals.max())
assert_array_equal(np.asarray(norm(vals)), [0, 1])
# Don't lose precision on longdoubles (float128 on Linux):
# for array inputs...
vals = np.array([1.2345678901, 9.8765432109], dtype=np.longdouble)
norm = mcolors.Normalize(vals.min(), vals.max())
assert_array_equal(np.asarray(norm(vals)), [0, 1])
# and for scalar ones.
eps = np.finfo(np.longdouble).resolution
norm = plt.Normalize(1, 1 + 100 * eps)
# This returns exactly 0.5 when longdouble is extended precision (80-bit),
# but only a value close to it when it is quadruple precision (128-bit).
assert 0 < norm(1 + 50 * eps) < 1
示例13: _shade_colors
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def _shade_colors(self, color, normals):
'''
Shade *color* using normal vectors given by *normals*.
*color* can also be an array of the same length as *normals*.
'''
shade = np.array([np.dot(n / proj3d.mod(n), [-1, -1, 0.5])
if proj3d.mod(n) else np.nan
for n in normals])
mask = ~np.isnan(shade)
if len(shade[mask]) > 0:
norm = Normalize(min(shade[mask]), max(shade[mask]))
shade[~mask] = min(shade[mask])
color = colorConverter.to_rgba_array(color)
# shape of color should be (M, 4) (where M is number of faces)
# shape of shade should be (M,)
# colors should have final shape of (M, 4)
alpha = color[:, 3]
colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
colors[:, 3] = alpha
else:
colors = np.asanyarray(color).copy()
return colors
示例14: plot_colormap
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def plot_colormap(cmap, continuous=True, discrete=True, ndisc=9):
"""Make a figure displaying the color map in continuous and/or discrete form
"""
nplots = int(continuous) + int(discrete)
fig, axx = plt.subplots(figsize=(6,.5*nplots), nrows=nplots, frameon=False)
axx = np.asarray(axx)
i=0
if continuous:
norm = mcolors.Normalize(vmin=0, vmax=1)
ColorbarBase(axx.flat[i], cmap=cmap, norm=norm, orientation='horizontal') ; i+=1
if discrete:
colors = cmap(np.linspace(0, 1, ndisc))
cmap_d = mcolors.ListedColormap(colors, name=cmap.name)
norm = mcolors.BoundaryNorm(np.linspace(0, 1, ndisc+1), len(colors))
ColorbarBase(axx.flat[i], cmap=cmap_d, norm=norm, orientation='horizontal')
for ax in axx.flat:
ax.set_axis_off()
fig.text(0.95, 0.5, cmap.name, va='center', ha='left', fontsize=12)
示例15: norm
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import Normalize [as 别名]
def norm(self, norm):
if norm == "lin":
self.pixels.norm = Normalize()
elif norm == "log":
self.pixels.norm = LogNorm()
self.pixels.autoscale() # this is to handle matplotlib bug #5424
elif norm == "symlog":
self.pixels.norm = SymLogNorm(linthresh=1.0)
self.pixels.autoscale()
elif isinstance(norm, Normalize):
self.pixels.norm = norm
else:
raise ValueError(
"Unsupported norm: '{}', options are 'lin',"
"'log','symlog', or a matplotlib Normalize object".format(norm)
)
self.update(force=True)
self.pixels.autoscale()