本文整理汇总了Python中matplotlib.collections.PatchCollection.set_clim方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_clim方法的具体用法?Python PatchCollection.set_clim怎么用?Python PatchCollection.set_clim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_clim方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: circles
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def circles(x, y, s, c='b', ax=None, vmin=None, vmax=None, **kwargs):
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection
import pylab as plt
if ax is None:
ax = plt.gca()
if isinstance(c,basestring):
color = c # ie. use colors.colorConverter.to_rgba_array(c)
else:
color = None # use cmap, norm after collection is created
kwargs.update(color=color)
if np.isscalar(x):
patches = [Circle((x, y), s),]
elif np.isscalar(s):
patches = [Circle((x_,y_), s) for x_,y_ in zip(x,y)]
else:
patches = [Circle((x_,y_), s_) for x_,y_,s_ in zip(x,y,s)]
collection = PatchCollection(patches, **kwargs)
if color is None:
collection.set_array(np.asarray(c))
if vmin is not None or vmax is not None:
collection.set_clim(vmin, vmax)
ax.add_collection(collection)
ax.autoscale_view()
return collection
示例2: circles
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def circles(x, y, s, c='b', vmin=None, vmax=None, **kwargs):
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection
if np.isscalar(c):
kwargs.setdefault('color', c)
c = None
if 'fc' in kwargs: kwargs.setdefault('facecolor', kwargs.pop('fc'))
if 'ec' in kwargs: kwargs.setdefault('edgecolor', kwargs.pop('ec'))
if 'ls' in kwargs: kwargs.setdefault('linestyle', kwargs.pop('ls'))
if 'lw' in kwargs: kwargs.setdefault('linewidth', kwargs.pop('lw'))
patches = [Circle((x_, y_), s_) for x_, y_, s_ in np.broadcast(x, y, s)]
collection = PatchCollection(patches, **kwargs)
if c is not None:
collection.set_array(np.asarray(c))
collection.set_clim(vmin, vmax)
ax = plt.gca()
ax.add_collection(collection)
ax.autoscale_view()
if c is not None:
plt.sci(collection)
return collection
示例3: plot2D
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def plot2D(patches, values, vmin, vmax):
color_map = plt.cm.get_cmap('plasma_r')
p = PatchCollection(patches, cmap=color_map, edgecolor="#ffffff", linewidth=0)
colors = values
p.set_array(np.array(colors))
ax = plt.axes()
ax.add_collection(p)
#plt.colorbar(p)
p.set_clim([vmin, vmax])
示例4: showStitchedModels
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def showStitchedModels(models, ax=None, x=None, cmin=None, cmax=None,
islog=True, title=None, cmap=jet):
"""show several 1d block models as (stitched) section"""
if x is None:
x = np.arange(len(models))
nlay = int(np.floor((len(models[0]) + 1) / 2.))
fig = None
if ax is None:
fig, ax = plt.subplots()
dxmed2 = np.median(np.diff(x)) / 2.
vals = np.zeros((len(models), nlay))
patches = []
maxz = 0.
for i, imod in enumerate(models):
if isinstance(imod, pg.RVector):
vals[i, :] = imod(nlay - 1, 2 * nlay - 1)
thk = np.asarray(imod(0, nlay - 1))
else:
vals[i, :] = imod[nlay - 1:2 * nlay - 1]
thk = imod[:nlay - 1]
thk = np.hstack((thk, thk[-1]*3))
z = np.hstack((0., np.cumsum(thk)))
maxz = max(maxz, z[-1])
for j in range(nlay):
rect = Rectangle((x[i] - dxmed2, z[j]), dxmed2 * 2, thk[j])
patches.append(rect)
p = PatchCollection(patches, cmap=cmap, linewidths=0)
if cmin is not None:
p.set_clim(cmin, cmax)
# p.set_array( np.log10( vals.ravel() ) )
setMappableData(p, vals.ravel(), logScale=islog)
ax.add_collection(p)
ax.set_ylim((maxz, 0.))
ax.set_xlim((min(x) - dxmed2, max(x) + dxmed2))
if title is not None:
ax.set_title(title)
pg.mplviewer.createColorbar(p, cMin=cmin, cMax=cmax, nLevs=5)
# cb = plt.colorbar(p, orientation='horizontal',aspect=50,pad=0.1)
# xt = [10, 20, 50, 100, 200, 500]
# cb.set_ticks( xt, [str(xti) for xti in xt] )
plt.draw()
return fig, ax
示例5: pcolor_rectangle
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def pcolor_rectangle(x, y, dx, dy, data, vmin=None, vmax=None, cmap=None, ncolors=256, norm=None):
if cmap is None:
cmap = cm.get_cmap(rcParams['image.cmap'], ncolors)
N = x.shape[0]
patch = []
for k in range(N):
rect = patches.Rectangle((x[k] - dx[k] / 2., y[k] - dy[k] / 2.), dx[k], dy[k])
patch.append(rect)
pcollection = PatchCollection(patch, cmap=cmap, edgecolor='none', norm=norm)
pcollection.set_array(data)
pcollection.set_clim(vmin, vmax)
return pcollection
示例6: plot_depth
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def plot_depth (mesh_path, fig_name, circumpolar=True):
# Plotting parameters
if circumpolar:
lat_max = -30 + 90
font_sizes = [240, 192, 160]
else:
font_sizes = [30, 24, 20]
# Build triangular patches for each element
elements, patches = make_patches(mesh_path, circumpolar)
# Find the depth of each element
elm_depth = []
for elm in elements:
depth1 = (elm.nodes[0].find_bottom()).depth
depth2 = (elm.nodes[1].find_bottom()).depth
depth3 = (elm.nodes[2].find_bottom()).depth
elm_depth.append(mean(array([depth1, depth2, depth3])))
# Set up figure
if circumpolar:
fig = figure(figsize=(128, 96))
ax = fig.add_subplot(1,1,1, aspect='equal')
else:
fig = figure(figsize=(16, 8))
ax = fig.add_subplot(1,1,1)
# Set colours for patches and add them to plot
img = PatchCollection(patches, cmap=jet)
img.set_array(array(elm_depth))
img.set_edgecolor('face')
ax.add_collection(img)
# Configure plot
if circumpolar:
xlim([-lat_max, lat_max])
ylim([-lat_max, lat_max])
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
axis('off')
else:
xlim([-180, 180])
ylim([-90, 90])
ax.get_xaxis().set_ticks(arange(-120,120+1,60))
ax.get_yaxis().set_ticks(arange(-60,60+1,30))
title('Seafloor depth (m)', fontsize=font_sizes[0])
cbar = colorbar(img)
cbar.ax.tick_params(labelsize=font_sizes[2])
img.set_clim(vmin=0, vmax=max(elm_depth))
savefig(fig_name)
示例7: __init__
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def __init__(
self,
ax,
data,
names=None,
pos=None,
cmap=None,
size=0.4,
vmin=0.0,
vmax=1.0,
make_patch=lambda x, y, sz: Circle((x, y), sz / 0.2),
):
""" Initialize the frame for
Create a polygon for each stock
"""
self.data = data
self.N, self.T = self.data.shape
self.offset = 0
if pos is None:
# Initial setup: Just place the nodes randomly
pos = np.zeros((self.N, 2))
pos[:, 0] = np.mod(np.arange(self.N), 10)
pos[:, 1] = np.arange(self.N) / 10
pos += 0.1 * np.random.randn(self.N, 2)
# Set axis limits
ax.set_xlim([np.amin(pos[:, 0]) - 1, np.amax(pos[:, 0]) + 1])
ax.set_ylim([np.amin(pos[:, 1]) - 1, np.amax(pos[:, 1]) + 1])
patches = []
for n in np.arange(self.N):
patch = make_patch(pos[n, 0], pos[n, 1], size)
patches.append(patch)
p = PatchCollection(patches, cmap=cmap, alpha=1.0)
# Set the values of the patches
p.set_array(self.data[:, 0])
p.set_clim(vmin, vmax)
ax.add_collection(p)
# Plot names above a few circles
if names is not None:
assert isinstance(names, list)
assert len(names) == self.N
for n, name in enumerate(names):
if name is not None:
ax.text(pos[n, 0], pos[n, 1], name, horizontalalignment="left", verticalalignment="top")
self.p = p
示例8: colored_bar
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def colored_bar(left, height, z=None, width=0.8, bottom=0, ax=None, maxgap=np.pi, **kwargs):
if ax is None:
ax = plt.gca()
width = itertools.cycle(np.atleast_1d(width))
bottom = itertools.cycle(np.atleast_1d(bottom))
rects = []
for x, y, h, w in zip(left, bottom, height, width):
rects.append(Rectangle((x, y), w, h))
# coll = PatchCollection(rects, array=z, **kwargs)
coll = PatchCollection(rects, **kwargs)
coll.set_array(z)
coll.set_clim([0, maxgap])
# coll.set_clim([0,maxgap])
ax.add_collection(coll)
ax.autoscale()
return coll
示例9: plot_num_layers
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def plot_num_layers (mesh_path, fig_name):
# Plotting parameters
circumpolar = True
lat_max = -30 + 90
font_sizes = [240, 192, 160]
# Build triangular patches for each element
elements, patches = make_patches(mesh_path, circumpolar)
# Calculate the number of layers for each element
num_layers = []
for elm in elements:
num_layers_elm = 0
# Count the number of layers for each node
for i in range(3):
node = elm.nodes[i]
num_layers_node = 1
# Iterate until we reach the bottom
while node.below is not None:
num_layers_node += 1
node = node.below
num_layers_elm = max(num_layers_elm, num_layers_node)
# Save the maximum number of layers across the 3 nodes
num_layers.append(num_layers_elm)
# Set up figure
fig = figure(figsize=(128, 96))
ax = fig.add_subplot(1,1,1, aspect='equal')
# Set colours for patches and add them to plot
img = PatchCollection(patches, cmap=jet)
img.set_array(array(num_layers))
img.set_edgecolor('face')
ax.add_collection(img)
# Configure plot
xlim([-lat_max, lat_max])
ylim([-lat_max, lat_max])
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
title('Ice shelf draft (m)', fontsize=font_sizes[0])
cbar = colorbar(img)
cbar.ax.tick_params(labelsize=font_sizes[2])
img.set_clim(vmin=1, vmax=47)
axis('off')
savefig(fig_name)
示例10: skypoly
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def skypoly(window, **kwargs):
from matplotlib.patches import Polygon
from matplotlib.collections import PolyCollection, PatchCollection
cmap = kwargs.pop('cmap',None)
if cmap is None:
cmap = copy.copy(pylab.cm.gray_r)
cmap.set_bad('r',1.0)
try:
ax = pylab.gca()['fk5']
except Exception as e:
# print e
ax = pylab.gca()
p,w = window.graphics(getweight=True)
if len(p) == 1: w = np.array([w])
vmin = kwargs.pop('vmin',np.max(w))
vmax = kwargs.pop('vmax',np.min(w))
if vmin==vmax:
vmin = vmax-1
# w = np.ones(len(p))
patches = []
for i,poly in enumerate(p):
ra,dec = poly['ra'], poly['dec']
patches.append(Polygon(zip(ra,dec), edgecolor='none', lw=0.01) )
tmp = {'cmap':cmap,
'rasterized': True,
'edgecolors':'none',
'antialiaseds':True,
}
tmp.update(kwargs)
p = PatchCollection(patches, **tmp)
p.set_array(w)
p.set_clim(vmin,vmax)
ax.add_collection(p)
ax.set_aspect('equal')
ax.set_rasterization_zorder(0)
return p
示例11: circle
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def circle(x, y, s, ax, fc='white', ec='dimgray', vmin=None, vmax=None, **kwargs):
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection
#http://stackoverflow.com/questions/9081553/python-scatter-plot-size-and-style-of-the-marker
patches = [Circle((x_,y_), s_) for x_,y_,s_ in zip(x,y,s)]
if type(fc) == list:
kwargs.update(edgecolor=ec, linestyle='-', antialiased=True)
collection = PatchCollection(patches, **kwargs)
collection.set_array(np.asarray(fc))
collection.set_clim(vmin, vmax)
else:
kwargs.update(edgecolor=ec, facecolor=fc, linestyle='-', antialiased=True)
collection = PatchCollection(patches, **kwargs)
ax.add_collection(collection)
return collection
示例12: __init__
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
class ArrayDisplay:
"""
Display a top-town view of a telescope array
"""
def __init__(self, telx, tely, mirrorarea,
axes=None, title="Array", autoupdate=True):
patches = [Circle(xy=(x, y), radius=np.sqrt(a))
for x, y, a in zip(telx, tely, mirrorarea)]
self.autoupdate = autoupdate
self.telescopes = PatchCollection(patches)
self.telescopes.set_clim(0, 100)
self.telescopes.set_array(np.zeros(len(telx)))
self.telescopes.set_cmap('spectral_r')
self.telescopes.set_edgecolor('none')
self.axes = axes if axes is not None else plt.gca()
self.axes.add_collection(self.telescopes)
self.axes.set_aspect(1.0)
self.axes.set_title(title)
self.axes.set_xlim(-1000, 1000)
self.axes.set_ylim(-1000, 1000)
self.bar = plt.colorbar(self.telescopes)
self.bar.set_label("Value")
@property
def values(self):
"""An array containing a value per telescope"""
return self.telescopes.get_array()
@values.setter
def values(self, values):
""" set the telescope colors to display """
self.telescopes.set_array(values)
self._update()
def _update(self):
""" signal a redraw if necessary """
if self.autoupdate:
plt.draw()
示例13: draw1DColumn
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [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
示例14: bwsalt
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def bwsalt (mesh_path, file_path, save=False, fig_name=None):
# Plotting parameters
lat_max = -30 + 90
circumpolar=True
# Build FESOM mesh
elements, patches = make_patches(mesh_path, circumpolar)
# Calculate annual average of bottom water temperature
file = Dataset(file_path, 'r')
data = mean(file.variables['salt'][:,:], axis=0)
file.close()
values = []
# Loop over elements
for elm in elements:
values_tmp = []
# For each component node, find the bottom index; average over
# all 3 such indices to get the value for this element
for node in elm.nodes:
id = node.find_bottom().id
values_tmp.append(data[id])
values.append(mean(values_tmp))
# Plot
fig = figure(figsize=(16,12))
ax = fig.add_subplot(1,1,1,aspect='equal')
img = PatchCollection(patches, cmap=jet)
img.set_array(array(values))
img.set_edgecolor('face')
img.set_clim(vmin=34, vmax=35)
ax.add_collection(img)
xlim([-lat_max, lat_max])
ylim([-lat_max, lat_max])
axis('off')
title(r'Bottom water temperature ($^{\circ}$C), annual average', fontsize=30)
cbar = colorbar(img)
cbar.ax.tick_params(labelsize=20)
if save:
fig.savefig(fig_name)
else:
fig.show()
示例15: draw
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_clim [as 别名]
def draw(self, colorbars=True, **kwargs):
"""Replace super().draw."""
self.cbars = []
clims = kwargs.get('clims', None)
n = len(self.collections)
if clims is None:
clims = [None]*n
elif len(clims) == 1:
clims = [clims[0]]*n
elif len(clims) == n:
pass
else:
raise RuntimeError('incorrect number of clims provided in draw')
for coll, cmap, label, clim in zip(self.collections, self.cmaps, self.cbar_labels, clims):
#print(clim)
pc = PatchCollection(coll, cmap=cmap)
pc.set_clim(vmin=clim[0],vmax=clim[1])
#print(pc.get_clim())
pc.set_array(np.array([p.value for p in coll]))
self._ax.add_collection(pc)
if colorbars:
options = {'orientation':'horizontal', 'pad':0.05, 'aspect':60,}
options.update(kwargs.get('colorbar-options', {}))
cbar = plt.colorbar(pc, **options)
cbar.set_label(label)
self.cbars.append(cbar)
fontdict = kwargs.get('font', {'color':'white'})
for s in self.squares:
if not s.label: continue
x = s.x + s.dx/2
y = s.y + s.dy/2
self._ax.text(x, y, s.label, ha='center', va='center', fontdict=fontdict)
qs_labels = [k.split('[')[0] for k in self.labels]
if self.guide_square:
self.guide_square.set_labels(qs_labels)
pc = PatchCollection(self.guide_square.patches, match_original=True)
self._ax.add_collection(pc)
self._ax.autoscale_view()