本文整理汇总了Python中matplotlib.patches.Polygon.set方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.set方法的具体用法?Python Polygon.set怎么用?Python Polygon.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Polygon
的用法示例。
在下文中一共展示了Polygon.set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unfolded
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set [as 别名]
# draw everything
xs = np.linspace(xknots[0],xknots[-1],200)
from scipy.integrate import quad
ymodel = nMC*Model(xs)/quad(Model,0,2)[0]
yprior = np.vectorize(lambda x: unfolded(refCoefs,x))(xs)
yfitted = np.vectorize(lambda x: folded (coefs,x))(xs[xs<1.8])
yunfolded = np.vectorize(lambda x: unfolded(coefs,x))(xs)
plt.figure(1)
from matplotlib.patches import Polygon
poly = Polygon(MakeSigmaPatch(unfolded, coefs, cov, xknots), closed=True)
poly.set(ec="b",fc="b",alpha=0.1,fill=True,zorder=0)
plt.gca().add_patch(poly)
plt.plot(xs,ymodel,"g--",lw=2,label="$t(x)$",zorder=1)
plt.plot(xs,yprior,"y",lw=3,label="$g(x)$",zorder=1)
plt.plot(xs[xs<1.8],yfitted,"r",lw=1,label="$f(y)$",zorder=3)
plt.plot(xs,yunfolded,"b",lw=2,label="$b(x)$",zorder=2)
xh, w, werr = GetScaledHistogram(data,bins=20,range=(folded.GetStart(),folded.GetStop()))
plt.errorbar(xh,w,werr,fmt="ko",capsize=0,label="data",zorder=4)
plt.ylim(ymin=0)
plt.xlabel("x")
示例2: MplPolygonalROI
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set [as 别名]
class MplPolygonalROI(AbstractMplRoi):
"""
Defines and displays polygonal ROIs on matplotlib plots
Attributes:
plot_opts: Dictionary instance
A dictionary of plot keywords that are passed to
the patch representing the ROI. These control
the visual properties of the ROI
"""
def __init__(self, axes):
"""
:param axes: A matplotlib Axes object to attach the graphical ROI to
"""
AbstractMplRoi.__init__(self, axes)
self.plot_opts = {'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR,
'alpha': 0.3}
self._setup_patch()
def _setup_patch(self):
self._patch = Polygon(np.array(list(zip([0, 1], [0, 1]))))
self._patch.set_zorder(100)
self._patch.set(**self.plot_opts)
self._axes.add_patch(self._patch)
self._patch.set_visible(False)
self._sync_patch()
def _roi_factory(self):
return PolygonalROI()
def _sync_patch(self):
# Update geometry
if not self._roi.defined():
self._patch.set_visible(False)
else:
x, y = self._roi.to_polygon()
self._patch.set_xy(list(zip(x + [x[0]],
y + [y[0]])))
self._patch.set_visible(True)
# Update appearance
self._patch.set(**self.plot_opts)
# Refresh
self._axes.figure.canvas.draw()
def start_selection(self, event):
if event.inaxes != self._axes:
return False
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
elif not self._roi.contains(event.xdata, event.ydata):
return False
self._roi_store()
if event.key == SCRUBBING_KEY:
self._scrubbing = True
self._cx = event.xdata
self._cy = event.ydata
else:
self.reset()
self._roi.add_point(event.xdata, event.ydata)
self._mid_selection = True
self._sync_patch()
def update_selection(self, event):
if not self._mid_selection or event.inaxes != self._axes:
return False
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
if self._scrubbing:
self._roi.move_to(event.xdata - self._cx,
event.ydata - self._cy)
self._cx = event.xdata
self._cy = event.ydata
else:
self._roi.add_point(event.xdata, event.ydata)
self._sync_patch()
def finalize_selection(self, event):
self._scrubbing = False
self._mid_selection = False
self._patch.set_visible(False)
self._axes.figure.canvas.draw()
示例3: MplPolygonalROI
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set [as 别名]
class MplPolygonalROI(AbstractMplRoi):
"""
Matplotlib ROI for polygon selections
Parameters
----------
axes : `~matplotlib.axes.Axes`
The Matplotlib axes to draw to.
roi : `~glue.core.roi.Roi`, optional
If specified, this ROI will be used and updated, otherwise a new one
will be created.
"""
_roi_cls = PolygonalROI
def __init__(self, axes, roi=None):
super(MplPolygonalROI, self).__init__(axes, roi=roi)
self.plot_opts = {'edgecolor': PATCH_COLOR,
'facecolor': PATCH_COLOR,
'alpha': 0.3}
self._patch = Polygon(np.array(list(zip([0, 1], [0, 1]))), zorder=100)
self._patch.set_visible(False)
self._axes.add_patch(self._patch)
def _sync_patch(self):
if self._roi.defined():
x, y = self._roi.to_polygon()
self._patch.set_xy(list(zip(x + [x[0]],
y + [y[0]])))
self._patch.set_visible(True)
self._patch.set(**self.plot_opts)
else:
self._patch.set_visible(False)
def start_selection(self, event, scrubbing=False):
if event.inaxes != self._axes:
return False
if scrubbing or event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
elif not self._roi.contains(event.xdata, event.ydata):
return False
self._store_previous_roi()
self._store_background()
if scrubbing or event.key == SCRUBBING_KEY:
self._scrubbing = True
self._cx = event.xdata
self._cy = event.ydata
else:
self.reset()
self._roi.add_point(event.xdata, event.ydata)
self._mid_selection = True
self._sync_patch()
self._draw()
def update_selection(self, event):
if not self._mid_selection or event.inaxes != self._axes:
return False
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
if self._scrubbing:
self._roi.move_to(event.xdata - self._cx,
event.ydata - self._cy)
self._cx = event.xdata
self._cy = event.ydata
else:
self._roi.add_point(event.xdata, event.ydata)
self._sync_patch()
self._draw()
def finalize_selection(self, event):
self._scrubbing = False
self._mid_selection = False
self._patch.set_visible(False)
self._draw()