本文整理汇总了Python中matplotlib.collections.PatchCollection.set_facecolors方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_facecolors方法的具体用法?Python PatchCollection.set_facecolors怎么用?Python PatchCollection.set_facecolors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_facecolors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_circles_for_scatter
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def get_circles_for_scatter(x, y, color='black', edgecolor='none', colormap='jet', radius=0.01, colornorm=None, alpha=1, radiusnorm=None, maxradius=1, minradius=0):
cmap = plt.get_cmap(colormap)
if colornorm is not None:
colornorm = plt.Normalize(colornorm[0], colornorm[1], clip=True)
# setup normalizing for radius scale factor (if used)
if type(radius) is list or type(radius) is np.array or type(radius) is np.ndarray:
if radiusnorm is None:
radiusnorm = matplotlib.colors.Normalize(np.min(radius), np.max(radius), clip=True)
else:
radiusnorm = matplotlib.colors.Normalize(radiusnorm[0], radiusnorm[1], clip=True)
# make circles
points = np.array([x, y]).T
circles = [None for i in range(len(x))]
for i, pt in enumerate(points):
if type(radius) is list or type(radius) is np.array or type(radius) is np.ndarray:
r = radiusnorm(radius[i])*(maxradius-minradius) + minradius
else:
r = radius
circles[i] = patches.Circle( pt, radius=r )
# make a collection of those circles
cc = PatchCollection(circles, cmap=cmap, norm=colornorm) # potentially useful option: match_original=True
# set properties for collection
cc.set_edgecolors(edgecolor)
if type(color) is list or type(color) is np.array or type(color) is np.ndarray:
cc.set_array(color)
else:
cc.set_facecolors(color)
cc.set_alpha(alpha)
return cc
示例2: add_pmts
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def add_pmts(ax=None, color='b', linewidth=1):
x0 = 27 # 9 times the inner radius
y0 = 6 * 3 * 2 / np.sqrt(3) # 6 times the outer radius
if ax is None:
ax = plt.gca()
per_row = [9, 10, 11, 10, 11, 10, 11, 10, 9]
polys = []
for row, num_pmts in enumerate(per_row):
y = row * 3 * np.sqrt(3)
for pmt in range(num_pmts):
x = 6 * pmt
if row in (0, 8):
x += 3
elif row % 2 == 0:
x -= 3
polys.append(RegularPolygon((x - x0, y - y0), 6, radius=6 / np.sqrt(3)))
col = PatchCollection(polys)
col.set_facecolors('none')
col.set_edgecolors(color)
col.set_linewidths(linewidth)
ax.add_artist(col)
return col
示例3: get_ellipses_for_scatter
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def get_ellipses_for_scatter(ax, x, y, color='black', edgecolor='none', colormap='jet', radius=0.01, colornorm=None, alpha=1, radiusnorm=None, maxradius=1, minradius=0):
# get ellipse size to make it a circle given axes
x0, y0 = ax.transAxes.transform((ax.get_ylim()[0],ax.get_xlim()[0]))
x1, y1 = ax.transAxes.transform((ax.get_ylim()[1],ax.get_xlim()[1]))
dx = x1-x0
dy = y1-y0
maxd = max(dx,dy)
cmap = plt.get_cmap(colormap)
if colornorm is not None:
colornorm = plt.Normalize(colornorm[0], colornorm[1], clip=True)
# setup normalizing for radius scale factor (if used)
if type(radius) is list or type(radius) is np.array or type(radius) is np.ndarray:
if radiusnorm is None:
radiusnorm = matplotlib.colors.Normalize(np.min(radius), np.max(radius), clip=True)
else:
radiusnorm = matplotlib.colors.Normalize(radiusnorm[0], radiusnorm[1], clip=True)
# make circles
points = np.array([x, y]).T
ellipses = [None for i in range(len(x))]
for i, pt in enumerate(points):
if type(radius) is list or type(radius) is np.array or type(radius) is np.ndarray:
r = radiusnorm(radius[i])*(maxradius-minradius) + minradius
else:
r = radius
width = r*2*maxd/dx
height = r*2*maxd/dy
ellipses[i] = patches.Ellipse( pt, width, height)
# make a collection of those circles
cc = PatchCollection(ellipses, cmap=cmap, norm=colornorm) # potentially useful option: match_original=True
# set properties for collection
cc.set_edgecolors(edgecolor)
if type(color) is list or type(color) is np.array or type(color) is np.ndarray:
cc.set_array(color)
else:
cc.set_facecolors(color)
cc.set_alpha(alpha)
return cc
示例4: render
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def render(self, patch_size=0.5, alpha=1.0, x_offset=100):
'''Draws the legend graphic and saves it to a file.'''
n = len(self.colors)
s = patch_size
# This offset is transformed to "data" coordinates (inches)
left_offset = (-s * 1.5) - (x_offset / self.dpi)
# Create grid to plot the artists
grid = np.concatenate((
np.zeros(n).reshape(n, 1),
np.arange(-n, 1)[1:].reshape(n, 1)
), axis=1)
plt.text(left_offset, 1.1, 'Legend', family='sans-serif',
size=14, weight='bold', color='#ffffff')
patches = []
for i in range(n):
# Add a rectangle
rect = mpatches.Rectangle(grid[i] - [0, 0], s, s, ec='none')
patches.append(rect)
self.__label__(grid[i], self.labels[i], x_offset)
collection = PatchCollection(patches, alpha=alpha)
# Space the patches and the text labels
collection.set_offset_position('data')
collection.set_offsets(np.array([
[left_offset, 0]
]))
collection.set_facecolors(self.colors)
#collection.set_edgecolor('#ffffff') # Draw color for box outlines
self.axis.add_collection(collection)
plt.axis('equal')
plt.axis('off')
plt.savefig(self.file_path, facecolor=self.bg_color, dpi=self.dpi,
pad_inches=0)
return self.file_path
示例5: scatter
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def scatter(ax, x, y, color='black', colormap='jet', radius=0.01, colornorm=None, alpha=1, radiusnorm=None, maxradius=1, minradius=0, edgecolors='none'):
# color can be array-like, or a matplotlib color
# I can't figure out how to control alpha through the individual circle patches.. it seems to get overwritten by the collection. low priority!
cmap = plt.get_cmap(colormap)
if colornorm is not None:
colornorm = plt.Normalize(colornorm[0], colornorm[1], clip=True)
# setup normalizing for radius scale factor (if used)
if type(radius) is list or type(radius) is np.array or type(radius) is np.ndarray:
if radiusnorm is None:
radiusnorm = matplotlib.colors.Normalize(np.min(radius), np.max(radius), clip=True)
else:
radiusnorm = matplotlib.colors.Normalize(radiusnorm[0], radiusnorm[1], clip=True)
# make circles
points = np.array([x, y]).T
circles = [None for i in range(len(x))]
for i, pt in enumerate(points):
if type(radius) is list or type(radius) is np.array or type(radius) is np.ndarray:
r = radiusnorm(radius[i])*(maxradius-minradius) + minradius
else:
r = radius
circles[i] = patches.Circle( pt, radius=r )
# make a collection of those circles
cc = PatchCollection(circles, cmap=cmap, norm=colornorm) # potentially useful option: match_original=True
# set properties for collection
cc.set_edgecolors(edgecolors)
if type(color) is list or type(color) is np.array or type(color) is np.ndarray:
cc.set_array(color)
else:
cc.set_facecolors(color)
cc.set_alpha(alpha)
# add collection to axis
ax.add_collection(cc)
示例6: get_wedges_for_heading_plot
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def get_wedges_for_heading_plot(x, y, color, orientation, size_radius=0.1, size_angle=20, colormap='jet', colornorm=None, size_radius_range=(0.01,.1), size_radius_norm=None, edgecolor='none', alpha=1, flip=True, deg=True, nskip=0, center_offset_fraction=0.75):
'''
Returns a Patch Collection of Wedges, with arbitrary color and orientation
Outputs:
Patch Collection
Inputs:
x, y - x and y positions (np.array or list, each of length N)
color - values to color wedges by (np.array or list, length N), OR color string.
colormap - specifies colormap to use (string, eg. 'jet')
norm - specifies range you'd like to normalize to,
if none, scales to min/max of color array (2-tuple, eg. (0,1) )
orientation - angles are in degrees, use deg=False to convert radians to degrees
size_radius - radius of wedge, in same units as x, y. Can be list or np.array, length N, for changing sizes
size_radius_norm - specifies range you'd like to normalize size_radius to, if size_radius is a list/array
should be tuple, eg. (0.01, .1)
size_angle - angular extent of wedge, degrees. Can be list or np.array, length N, for changing sizes
edgecolor - color for lineedges, string or np.array of length N
alpha - transparency (single value, between 0 and 1)
flip - flip orientations by 180 degrees, default = True
nskip - allows you to skip between points to make the points clearer, nskip=1 skips every other point
center_offset_fraction - (float in range (0,1) ) - 0 means (x,y) is at the tip, 1 means (x,y) is at the edge
'''
cmap = plt.get_cmap(colormap)
# norms
if colornorm is None and type(color) is not str:
colornorm = plt.Normalize(np.min(color), np.max(color))
elif type(color) is not str:
colornorm = plt.Normalize(colornorm[0], colornorm[1])
if size_radius_norm is None:
size_radius_norm = plt.Normalize(np.min(size_radius), np.max(size_radius), clip=True)
else:
size_radius_norm = plt.Normalize(size_radius_norm[0], size_radius_norm[1], clip=True)
indices_to_plot = np.arange(0, len(x), nskip+1)
# fix orientations
if type(orientation) is list:
orientation = np.array(orientation)
if deg is False:
orientation = orientation*180./np.pi
if flip:
orientation += 180
flycons = []
n = 0
for i in indices_to_plot:
# wedge parameters
if type(size_radius) is list or type(size_radius) is np.array or type(size_radius) is np.ndarray:
r = size_radius_norm(size_radius[i])*(size_radius_range[1]-size_radius_range[0]) + size_radius_range[0]
else: r = size_radius
if type(size_angle) is list or type(size_angle) is np.array or type(size_angle) is np.ndarray:
angle_swept = size_radius[i]
else: angle_swept = size_radius
theta1 = orientation[i] - size_angle/2.
theta2 = orientation[i] + size_angle/2.
center = [x[i], y[i]]
center[0] -= np.cos(orientation[i]*np.pi/180.)*r*center_offset_fraction
center[1] -= np.sin(orientation[i]*np.pi/180.)*r*center_offset_fraction
wedge = patches.Wedge(center, r, theta1, theta2)
flycons.append(wedge)
# add collection and color it
pc = PatchCollection(flycons, cmap=cmap, norm=colornorm)
# set properties for collection
pc.set_edgecolors(edgecolor)
if type(color) is list or type(color) is np.array or type(color) is np.ndarray:
if type(color) is list:
color = np.asarray(color)
pc.set_array(color[indices_to_plot])
else:
pc.set_facecolors(color)
pc.set_alpha(alpha)
return pc
示例7: circles
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_facecolors [as 别名]
def circles(x, y, s, c='b', vmin=None, vmax=None, **kwargs):
"""
Make a scatter of circles plot of x vs y, where x and y are sequence
like objects of the same lengths. The size of circles are in data scale.
Parameters
----------
x,y : scalar or array_like, shape (n, )
Input data
s : scalar or array_like, shape (n, )
Radius of circle in data unit.
c : color or sequence of color, optional, default : 'b'
`c` can be a single color format string, or a sequence of color
specifications of length `N`, or a sequence of `N` numbers to be
mapped to colors using the `cmap` and `norm` specified via kwargs.
Note that `c` should not be a single numeric RGB or RGBA sequence
because that is indistinguishable from an array of values
to be colormapped. (If you insist, use `color` instead.)
`c` can be a 2-D array in which the rows are RGB or RGBA, however.
vmin, vmax : scalar, optional, default: None
`vmin` and `vmax` are used in conjunction with `norm` to normalize
luminance data. If either are `None`, the min and max of the
color array is used.
kwargs : `~matplotlib.collections.Collection` properties
Eg. alpha, edgecolor(ec), facecolor(fc), linewidth(lw), linestyle(ls),
norm, cmap, transform, etc.
Returns
-------
paths : `~matplotlib.collections.PathCollection`
Examples
--------
a = np.arange(11)
circles(a, a, a*0.2, c=a, alpha=0.5, edgecolor='none')
plt.colorbar()
License
--------
This code is under [The BSD 3-Clause License]
(http://opensource.org/licenses/BSD-3-Clause)
"""
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)
collection.set_facecolors('none')
collection.set_facecolor('none')
if (kwargs['facecolor'] != 'none'):
collection.set_facecolors(kwargs['facecolor']);
collection.set_facecolor(kwargs['facecolor']);
ax = plt.gca()
ax.add_collection(collection)
ax.autoscale_view()
if c is not None:
plt.sci(collection)
return collection