本文整理汇总了Python中matplotlib.collections.PatchCollection.set_pickradius方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_pickradius方法的具体用法?Python PatchCollection.set_pickradius怎么用?Python PatchCollection.set_pickradius使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_pickradius方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: str
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_pickradius [as 别名]
#.........这里部分代码省略.........
else:
self.image = np.zeros_like(self.geom.pix_id, dtype=np.float)
self.norm = norm
def highlight_pixels(self, pixels, color='g', linewidth=1, alpha=0.75):
'''
Highlight the given pixels with a colored line around them
Parameters
----------
pixels : index-like
The pixels to highlight.
Can either be a list or array of integers or a
boolean mask of length number of pixels
color: a matplotlib conform color
the color for the pixel highlighting
linewidth: float
linewidth of the highlighting in points
alpha: 0 <= alpha <= 1
The transparency
'''
l = np.zeros_like(self.image)
l[pixels] = linewidth
self.pixel_highlighting.set_linewidth(l)
self.pixel_highlighting.set_alpha(alpha)
self.pixel_highlighting.set_edgecolor(color)
self._update()
def enable_pixel_picker(self):
""" enable ability to click on pixels """
self.pixels.set_picker(True) # enable click
self.pixels.set_pickradius(sqrt(u.Quantity(self.geom.pix_area[0])
.value) / np.pi)
self.pixels.set_snap(True) # snap cursor to pixel center
self.axes.figure.canvas.mpl_connect('pick_event', self._on_pick)
def set_limits_minmax(self, zmin, zmax):
""" set the color scale limits from min to max """
self.pixels.set_clim(zmin, zmax)
self.autoscale = False
self._update()
def set_limits_percent(self, percent=95):
""" auto-scale the color range to percent of maximum """
zmin = self.pixels.get_array().min()
zmax = self.pixels.get_array().max()
dz = zmax - zmin
frac = percent / 100.0
self.autoscale = False
self.set_limits_minmax(zmin, zmax - (1.0 - frac) * dz)
@property
def norm(self):
'''
The norm instance of the Display
Possible values:
- "lin": linear scale
- "log": log scale (cannot have negative values)
- "symlog": symmetric log scale (negative values are ok)
- any matplotlib.colors.Normalize instance, e. g. PowerNorm(gamma=-2)
'''
return self.pixels.norm
示例2: bool
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_pickradius [as 别名]
#.........这里部分代码省略.........
self.axes.set_aspect('equal', 'datalim')
self.axes.set_title(title)
self.axes.set_xlabel("X position ({})".format(self.geom.pix_x.unit))
self.axes.set_ylabel("Y position ({})".format(self.geom.pix_y.unit))
self.axes.autoscale_view()
# set up a patch to display when a pixel is clicked (and
# pixel_picker is enabled):
self._active_pixel = copy.copy(patches[0])
self._active_pixel.set_facecolor('r')
self._active_pixel.set_alpha(0.5)
self._active_pixel.set_linewidth(2.0)
self._active_pixel.set_visible(False)
self.axes.add_patch(self._active_pixel)
self._active_pixel_label = plt.text(self._active_pixel.xy[0],
self._active_pixel.xy[1],
"0",
horizontalalignment='center',
verticalalignment='center')
self._active_pixel_label.set_visible(False)
# enable ability to click on pixel and do something (can be
# enabled on-the-fly later as well:
if allow_pick:
self.enable_pixel_picker()
def enable_pixel_picker(self):
""" enable ability to click on pixels """
self.pixels.set_picker(True) # enable click
self.pixels.set_pickradius(sqrt(u.Quantity(self.geom.pix_area[0])
.value) / np.pi)
self.pixels.set_snap(True) # snap cursor to pixel center
self.axes.figure.canvas.mpl_connect('pick_event', self._on_pick)
def set_cmap(self, cmap):
""" Change the color map
Parameters
----------
self: type
description
cmap: `matplotlib.colors.ColorMap`
a color map, e.g. from `matplotlib.pyplot.cm.*`
"""
self.pixels.set_cmap(cmap)
def set_image(self, image):
"""
Change the image displayed on the Camera.
Parameters
----------
image: array_like
array of values corresponding to the pixels in the CameraGeometry.
"""
image = np.asanyarray(image)
if image.shape != self.geom.pix_x.shape:
raise ValueError("Image has a different shape {} than the"
"given CameraGeometry {}"
.format(image.shape, self.geom.pix_x.shape))
self.pixels.set_array(image)
self.update()