本文整理汇总了Python中matplotlib.patches.Rectangle.set_clip_box方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_clip_box方法的具体用法?Python Rectangle.set_clip_box怎么用?Python Rectangle.set_clip_box使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_clip_box方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: highlight_artist
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
def highlight_artist(self, val, artist=None):
# print val, artist
figure=self.get_figpage()._artists[0]
ax = self.get_figaxes()
if artist is None:
alist=self._artists
else:
alist=artist
if val == True:
container = self.get_container()
if container is None: return
de = self.get_data_extent()
from ifigure.matplotlib_mod.art3d_gl import AxesImageGL
if isinstance(alist[0], AxesImageGL):
hl = alist[0].add_hl_mask()
for item in hl:
alist[0].figobj_hl.append(item)
# hl = alist[0].make_hl_artist(container)
# rect_alpha = 0.0
else:
x=[de[0],de[1],de[1],de[0],de[0]]
y=[de[2],de[2],de[3],de[3],de[2]]
hl= container.plot(x, y, marker='s',
color='k', linestyle='None',
markerfacecolor='None',
markeredgewidth = 0.5,
scalex=False, scaley=False)
rect_alpha = 0.3
hlp = Rectangle((de[0],de[2]),
de[1]-de[0],
de[3]-de[2],
alpha=rect_alpha, facecolor='k',
figure = figure,
transform= container.transData)
if ax is not None:
x0, y0 = ax._artists[0].transAxes.transform((0,0))
x1, y1 = ax._artists[0].transAxes.transform((1,1))
bbox = Bbox([[x0,y0],[x1,y1]])
hlp.set_clip_box(bbox)
hlp.set_clip_on(True)
figure.patches.append(hlp)
for item in (hl[0], hlp):
alist[0].figobj_hl.append(item)
else:
for a in alist:
if len(a.figobj_hl) != 0:
a.figobj_hl[0].remove()
figure.patches.remove(a.figobj_hl[1])
a.figobj_hl=[]
示例2: on_press
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
def on_press(event):
global id_motion, xs, ys, r
print 'INAXES: ', event.inaxes
if event.inaxes!=ax: return
xs, ys = event.xdata, event.ydata
print 'PRESS button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (
event.button, event.x, event.y, event.xdata, event.ydata)
r = Rectangle(xy=(xs,ys), height=0, width=0, fill=False, lw=2, alpha=0.2)
ax.add_artist(r)
r.set_clip_box(ax.bbox)
draw()
id_motion = fig.canvas.mpl_connect('motion_notify_event', on_motion)
示例3: boundingBox
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
def boundingBox(self, data, ax, label, bBoundingBoxes, bLabels):
''' Draw bounding box around data.'''
data = np.array(data)
width = max(data[:,0]) - min(data[:,0])
height = max(data[:,1]) - min(data[:,1])
r = Rectangle((min(data[:,0]), min(data[:,1])), width, height)
if bBoundingBoxes:
ax.add_artist(r)
r.set_clip_box(ax.bbox)
r.set_alpha(0.1)
r.set_facecolor((0.5, 0.5, 0.5))
if bLabels:
ax.annotate(label, xy = (min(data[:,0]), max(data[:,1])), xytext = (0, 0),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = (0.5, 0.5, 0.5), alpha = 0.1))
示例4: rectSelection
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
class rectSelection(GuiSelection):
"""Interactive selection of a rectangular region on the axis.
Used by hist2d_alex().
"""
def on_press_draw(self):
if 'r' in self.__dict__:
self.r.set_height(0)
self.r.set_width(0)
self.r.set_xy((self.xs, self.ys))
self.e.height = 0
self.e.width = 0
self.e.center = (self.xs, self.ys)
else:
self.r = Rectangle(xy=(self.xs, self.ys), height=0, width=0,
fill=False, lw=2, alpha=0.5, color='blue')
self.e = Ellipse(xy=(self.xs, self.ys), height=0, width=0,
fill=False, lw=2, alpha=0.6, color='blue')
self.ax.add_artist(self.r)
self.ax.add_artist(self.e)
self.r.set_clip_box(self.ax.bbox)
self.r.set_zorder(10)
self.e.set_clip_box(self.ax.bbox)
self.e.set_zorder(10)
def on_motion_draw(self):
self.r.set_height(self.ye - self.ys)
self.r.set_width(self.xe - self.xs)
self.e.height = (self.ye - self.ys)
self.e.width = (self.xe - self.xs)
self.e.center = (np.mean([self.xs, self.xe]),
np.mean([self.ys, self.ye]))
self.fig.canvas.draw()
def on_release_print(self):
# This is the only custom method for hist2d_alex()
E1, E2 = min((self.xs, self.xe)), max((self.xs, self.xe))
S1, S2 = min((self.ys, self.ye)), max((self.ys, self.ye))
self.selection = dict(E1=E1, E2=E2, S1=S1, S2=S2)
pprint("Selection: \nE1=%.2f, E2=%.2f, S1=%.2f, S2=%.2f\n" %\
(E1,E2,S1,S2))
示例5: highlight_artist
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
def highlight_artist(self, val, artist=None):
figure=self.get_figpage()._artists[0]
ax = self.get_figaxes()
if val:
if len(self._artists[0].figobj_hl) != 0: return
box = self.get_artist_extent_all()
self._artist_extent = box
if box[0] is None: return
x = [box[0], box[0], box[1], box[1], box[0]]
y = [box[3], box[2], box[2], box[3], box[3]]
hl= Line2D(x, y, marker='s',
color='k', linestyle='None',
markerfacecolor='k',
markeredgewidth = 0.5,
figure=figure, alpha=0.3)
figure.lines.append(hl)
xy = (box[0], box[2])
w = box[1] - box[0]
h = box[3] - box[2]
hlp = Rectangle(xy, w, h, alpha=0.3, facecolor='k',
figure = figure)
if ax is not None:
x0, y0 = ax._artists[0].transAxes.transform((0,0))
x1, y1 = ax._artists[0].transAxes.transform((1,1))
bbox = Bbox([[x0,y0],[x1,y1]])
hlp.set_clip_box(bbox)
hlp.set_clip_on(True)
figure.patches.append(hlp)
# if ax is not None and ax.get_3d():
# import mpl_toolkits.mplot3d.art3d as art3d
# art3d.patch_2d_to_3d(hl)
# if len(ax._artists) != 0:
# a.axes = self.get_figaxes()._artists[0]
self._artists[0].figobj_hl.extend([hl, hlp])
else:
if len(self._artists[0].figobj_hl) == 2:
figure.lines.remove(self._artists[0].figobj_hl[0])
figure.patches.remove(self._artists[0].figobj_hl[1])
self._artists[0].figobj_hl = []
示例6: xspanSelection
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
class xspanSelection(GuiSelection):
"""Interactive selection of an x range on the axis"""
def on_press_draw(self):
if 'r' in self.__dict__:
self.r.set_width(0)
self.r.set_xy((self.xs, self.ax.get_ylim()[0]))
self.r.set_height(self.ax.get_ylim()[1] - self.ax.get_ylim()[0])
else:
self.r = Rectangle(xy=(self.xs, self.ax.get_ylim()[0]),
height=self.ax.get_ylim()[1] - \
self.ax.get_ylim()[0],
width=0, fill=True, lw=2, alpha=0.5,
color='blue')
self.ax.add_artist(self.r)
self.r.set_clip_box(self.ax.bbox)
self.r.set_zorder(10)
def on_motion_draw(self):
self.r.set_width(self.xe - self.xs)
def on_release_print(self):
pprint('X Span: (%d, %d)\n' % (self.xs, self.xe))
示例7: highlight_artist
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
def highlight_artist(self, val, artist=None):
from ifigure.matplotlib_mod.art3d_gl import Poly3DCollectionGL
from ifigure.matplotlib_mod.art3d_gl import Line3DCollectionGL
figure=self.get_figpage()._artists[0]
ax = self.get_figaxes()
if artist is None:
alist=self._artists
else:
alist=artist
if val == True:
if self._parent is None: return
container = self.get_container()
if container is None: return
if isinstance(alist[0], Poly3DCollectionGL):
hl = alist[0].add_hl_mask()
for item in hl:
alist[0].figobj_hl.append(item)
else:
de = self.get_data_extent()
x=(de[0], de[1],de[1],de[0],de[0])
y=(de[2], de[2],de[3],de[3],de[2])
facecolor='k'
if isinstance(alist[0], Poly3DCollectionGL):
hl = alist[0].make_hl_artist(container)
facecolor = 'none'
self._hit_path = None
elif isinstance(alist[0], Line3DCollectionGL):
hl = alist[0].make_hl_artist(container)
facecolor = 'none'
self._hit_path = None
else:
hl= container.plot(x, y, marker='s',
color='k', linestyle='None',
markerfacecolor='None',
markeredgewidth = 0.5,
scalex=False, scaley=False)
for item in hl:
alist[0].figobj_hl.append(item)
if self._hit_path is not None:
v = self._hit_path.vertices
hl= container.plot(v[:,0], v[:,1], marker='s',
color='k', linestyle='None',
markerfacecolor='None',
markeredgewidth = 0.5,
scalex=False, scaley=False)
for item in hl:
alist[0].figobj_hl.append(item)
hlp = Rectangle((de[0],de[2]),
de[1]-de[0],
de[3]-de[2],
alpha=0.3, facecolor=facecolor,
figure = figure,
transform= container.transData)
if ax is not None:
x0, y0 = ax._artists[0].transAxes.transform((0,0))
x1, y1 = ax._artists[0].transAxes.transform((1,1))
bbox = Bbox([[x0,y0],[x1,y1]])
hlp.set_clip_box(bbox)
hlp.set_clip_on(True)
figure.patches.append(hlp)
alist[0].figobj_hl.append(hlp)
else:
for a in alist:
if len(a.figobj_hl) == 0: continue
for hl in a.figobj_hl[:-1]:
hl.remove()
if isinstance(alist[0], Poly3DCollectionGL):
a.figobj_hl[-1].remove()
else:
figure.patches.remove(a.figobj_hl[-1])
a.figobj_hl=[]
示例8: _init_legend_box
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
def _init_legend_box(self, handles, labels):
"""
Initiallize the legend_box. The legend_box is an instance of
the OffsetBox, which is packed with legend handles and
texts. Once packed, their location is calculated during the
drawing time.
"""
fontsize = self.fontsize
# legend_box is a HPacker, horizontally packed with
# columns. Each column is a VPacker, vertically packed with
# legend items. Each legend item is HPacker packed with
# legend handleBox and labelBox. handleBox is an instance of
# offsetbox.DrawingArea which contains legend handle. labelBox
# is an instance of offsetbox.TextArea which contains legend
# text.
text_list = [] # the list of text instances
handle_list = [] # the list of text instances
label_prop = dict(verticalalignment='baseline',
horizontalalignment='left',
fontproperties=self.prop,
)
labelboxes = []
for l in labels:
textbox = TextArea(l, textprops=label_prop,
multilinebaseline=True, minimumdescent=True)
text_list.append(textbox._text)
labelboxes.append(textbox)
handleboxes = []
# The approximate height and descent of text. These values are
# only used for plotting the legend handle.
height = self._approx_text_height() * 0.7
descent = 0.
# each handle needs to be drawn inside a box of (x, y, w, h) =
# (0, -descent, width, height). And their corrdinates should
# be given in the display coordinates.
# NOTE : the coordinates will be updated again in
# _update_legend_box() method.
# The transformation of each handle will be automatically set
# to self.get_trasnform(). If the artist does not uses its
# default trasnform (eg, Collections), you need to
# manually set their transform to the self.get_transform().
for handle in handles:
if isinstance(handle, RegularPolyCollection):
npoints = self.scatterpoints
else:
npoints = self.numpoints
if npoints > 1:
# we put some pad here to compensate the size of the
# marker
xdata = np.linspace(0.3*fontsize,
(self.handlelength-0.3)*fontsize,
npoints)
xdata_marker = xdata
elif npoints == 1:
xdata = np.linspace(0, self.handlelength*fontsize, 2)
xdata_marker = [0.5*self.handlelength*fontsize]
if isinstance(handle, Line2D):
ydata = ((height-descent)/2.)*np.ones(xdata.shape, float)
legline = Line2D(xdata, ydata)
legline.update_from(handle)
self._set_artist_props(legline) # after update
legline.set_clip_box(None)
legline.set_clip_path(None)
legline.set_drawstyle('default')
legline.set_marker('None')
handle_list.append(legline)
legline_marker = Line2D(xdata_marker, ydata[:len(xdata_marker)])
legline_marker.update_from(handle)
self._set_artist_props(legline_marker)
legline_marker.set_clip_box(None)
legline_marker.set_clip_path(None)
legline_marker.set_linestyle('None')
# we don't want to add this to the return list because
# the texts and handles are assumed to be in one-to-one
# correpondence.
legline._legmarker = legline_marker
elif isinstance(handle, Patch):
p = Rectangle(xy=(0., 0.),
width = self.handlelength*fontsize,
height=(height-descent),
)
#.........这里部分代码省略.........
示例9: addEntry
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_clip_box [as 别名]
addEntry('Car Battery With CFL', cost = 1.0, cpLh = 0.12)
#addEntry('SharedSolar With CFL', cost = 1.0, cpLh = 0.10)
#addEntry('Grid Mali With CFL', cost = 16, cpLh = 16/0.2)
fig = plt.figure()
axes = fig.add_subplot(111)
for key in dict.keys():
axes.loglog(dict[key]['cost'], dict[key]['cpLh'], 'ko')
axes.text(dict[key]['cost'], dict[key]['cpLh'], key)
from matplotlib.patches import Rectangle
rect = Rectangle((1, .017), 5, .07, facecolor="#dddddd")
axes.add_artist(rect)
rect.set_clip_box(axes.bbox)
axes.text(1.1,0.03, 'Shared Solar With CFL')
plt.xlim((0.1,10))
plt.ylim((0.01,10))
plt.title('Lumen-Hour Cost vs. Purchase Price')
plt.xlabel('Purchase Cost (USD)')
plt.ylabel('Cost Per Lumen-Hour')
plt.grid()
plt.savefig('costVsLumens.pdf')
plt.show()
plt.close()