本文整理汇总了Python中matplotlib.image.BboxImage类的典型用法代码示例。如果您正苦于以下问题:Python BboxImage类的具体用法?Python BboxImage怎么用?Python BboxImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BboxImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: imagesAtPositions
def imagesAtPositions(ax, images, positions):
for s in range(len(positions)):
#print(positions[s,:])
bbox = Bbox(corners(ax, positions[s,:],20))
bbox_image = BboxImage(bbox)
image = imread(images[s])
bbox_image.set_data(image)
ax.add_artist(bbox_image)
示例2: _init_bbox_image
def _init_bbox_image(self, im):
bbox_image = BboxImage(self.get_window_extent,
norm = None,
origin=None,
)
bbox_image.set_transform(IdentityTransform())
bbox_image.set_data(im)
self.bbox_image = bbox_image
示例3: draw
def draw(self, renderer, *args, **kwargs):
bbox = self.get_window_extent(renderer)
stretch_factor = bbox.height / bbox.width
ny = int(stretch_factor*self._ribbonbox.nx)
if self._cached_ny != ny:
arr = self._ribbonbox.get_stretched_image(stretch_factor)
self.set_array(arr)
self._cached_ny = ny
BboxImage.draw(self, renderer, *args, **kwargs)
示例4: test_bbox_image_inverted
def test_bbox_image_inverted():
# This is just used to produce an image to feed to BboxImage
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot([1, 2, 3])
im_buffer = io.BytesIO()
fig.savefig(im_buffer)
im_buffer.seek(0)
image = imread(im_buffer)
bbox_im = BboxImage(Bbox([[100, 100], [0, 0]]))
bbox_im.set_data(image)
axes.add_artist(bbox_im)
示例5: __init__
def __init__(self, arr,
zoom=1,
cmap = None,
norm = None,
interpolation=None,
origin=None,
filternorm=1,
filterrad=4.0,
resample = False,
dpi_cor=True,
**kwargs
):
self._dpi_cor = dpi_cor
self.image = BboxImage(bbox=self.get_window_extent,
cmap = cmap,
norm = norm,
interpolation=interpolation,
origin=origin,
filternorm=filternorm,
filterrad=filterrad,
resample = resample,
**kwargs
)
self._children = [self.image]
self.set_zoom(zoom)
self.set_data(arr)
OffsetBox.__init__(self)
示例6: test_bbox_image_inverted
def test_bbox_image_inverted():
# This is just used to produce an image to feed to BboxImage
image = np.arange(100).reshape((10, 10))
ax = plt.subplot(111)
bbox_im = BboxImage(TransformedBbox(Bbox([[100, 100], [0, 0]]), ax.transData))
bbox_im.set_data(image)
bbox_im.set_clip_on(False)
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.add_artist(bbox_im)
image = np.identity(10)
bbox_im = BboxImage(TransformedBbox(Bbox([[0.1, 0.2], [0.3, 0.25]]), ax.figure.transFigure))
bbox_im.set_data(image)
bbox_im.set_clip_on(False)
ax.add_artist(bbox_im)
示例7: imagesAsTickMarks
def imagesAsTickMarks(ax, images):
TICKYPOS = -.6
lowerCorner = ax.transData.transform((.8,TICKYPOS-.2))
upperCorner = ax.transData.transform((1.2,TICKYPOS+.2))
print(lowerCorner)
print(upperCorner)
bbox_image = BboxImage(Bbox([lowerCorner[0],
lowerCorner[1],
upperCorner[0],
upperCorner[1],
]),
norm = None,
origin=None,
clip_on=False,
)
image = imread(images[0])
print('img loaded')
bbox_image.set_data(image)
ax.add_artist(bbox_image)
示例8: __init__
def __init__(self, bbox, color,
cmap = None,
norm = None,
interpolation=None,
origin=None,
filternorm=1,
filterrad=4.0,
resample = False,
**kwargs
):
BboxImage.__init__(self, bbox,
cmap = cmap,
norm = norm,
interpolation=interpolation,
origin=origin,
filternorm=filternorm,
filterrad=filterrad,
resample = resample,
**kwargs
)
self._ribbonbox = RibbonBox(color)
self._cached_ny = None
示例9: plot_wind_data2
def plot_wind_data2(ax, so, time_nums):
so.wind_speed = np.array(so.wind_speed)
wind_speed_max = np.nanmax(so.wind_speed)
print('max speed', wind_speed_max, len(so.wind_speed))
logo = image.imread('north.png', None)
bbox2 = Bbox.from_bounds(210, 330, 30, 40)
# trans_bbox2 = bbox2.transformed(ax.transData)
bbox_image2 = BboxImage(bbox2)
bbox_image2.set_data(logo)
ax.add_image(bbox_image2)
# for x in range(0,len(time_nums),100):
U = so.u
V = so.v
# if x == max_index:
Q = ax.quiver(time_nums, -.15, U, V, headlength=0,
headwidth=0, headaxislength=0, alpha=1, color='#045a8d', width=.0015, scale=wind_speed_max*5)
ax.quiverkey(Q, 0.44, 0.84, wind_speed_max * .6,labelpos='N',label = ' 0 mph %.2f mph' % wind_speed_max,
# fontproperties={'weight': 'bold'}
)
示例10: BboxImage
#plt.gca().get_xaxis().set_ticklabels([])
# lowerCorner = difP.transData.transform((.8,TICKYPOS-.2))
# upperCorner = difP.transData.transform((1.2,TICKYPOS+.2))
lowPos = [0,TICKYPOS-1.2]
upPos = [lowPos[0]+1.2,lowPos[1]+1.2]
print lowPos
print upPos
lowerCorner = plt.gca().transData.transform((lowPos[0],lowPos[1]))
upperCorner = plt.gca().transData.transform((upPos[0],upPos[1]))
# first
bbox_image0 = BboxImage(Bbox([[lowerCorner[0], lowerCorner[1]],
[upperCorner[0], upperCorner[1]]]),
norm = None,
origin=None,
clip_on=False,
)
bbox_image0.set_data(imread('../thesis/pictures/statePics/set14/set14_0.jpg'))
plt.gca().add_artist(bbox_image0)
# second
#lowC1 = plt.gca().transData.transform((lowPos[0]+6.5,lowPos[1]))
#upC1 = plt.gca().transData.transform((upPos[0]+6.5,upPos[1]))
#bbox_image1 = BboxImage(Bbox([[lowC1[0], lowC1[1]],
# [upC1[0], upC1[1]]]),
# norm = None,
# origin=None,
# clip_on=False,
# )
#bbox_image1.set_data(imread('../thesis/pictures/statePics/set14/set14_1.jpg'))
#plt.gca().add_artist(bbox_image1)
示例11: imread
# bbox_image.set_data(
# imread(
# "emoji/images/%s.png" % names[i]
# )
# )
# f.add_artist(bbox_image)
# print("emoji/images/%s.png" % names[i])
lowerCorner = f.transData.transform((.8,LABEL_Y_POS-.225))
upperCorner = f.transData.transform((1.2,LABEL_Y_POS+.225))
bbox_image = BboxImage(Bbox([[lowerCorner[0],
lowerCorner[1]],
[upperCorner[0],
upperCorner[1]],
]),
norm = None,
origin=None,
clip_on=False,
)
bbox_image.set_data(imread('emoji/images/1f602.png'))
f.add_artist(bbox_image)
# f.xticks(_rl(data), names)
plt.title("emojis!!!")
plt.show()
示例12: OffsetImage
class OffsetImage(OffsetBox):
def __init__(self, arr,
zoom=1,
cmap = None,
norm = None,
interpolation=None,
origin=None,
filternorm=1,
filterrad=4.0,
resample = False,
dpi_cor=True,
**kwargs
):
self._dpi_cor = dpi_cor
self.image = BboxImage(bbox=self.get_window_extent,
cmap = cmap,
norm = norm,
interpolation=interpolation,
origin=origin,
filternorm=filternorm,
filterrad=filterrad,
resample = resample,
**kwargs
)
self._children = [self.image]
self.set_zoom(zoom)
self.set_data(arr)
OffsetBox.__init__(self)
def set_data(self, arr):
self._data = np.asarray(arr)
self.image.set_data(self._data)
def get_data(self):
return self._data
def set_zoom(self, zoom):
self._zoom = zoom
def get_zoom(self):
return self._zoom
# def set_axes(self, axes):
# self.image.set_axes(axes)
# martist.Artist.set_axes(self, axes)
# def set_offset(self, xy):
# """
# set offset of the container.
# Accept : tuple of x,y cooridnate in disokay units.
# """
# self._offset = xy
# self.offset_transform.clear()
# self.offset_transform.translate(xy[0], xy[1])
def get_offset(self):
"""
return offset of the container.
"""
return self._offset
def get_children(self):
return [self.image]
def get_window_extent(self, renderer):
'''
get the bounding box in display space.
'''
w, h, xd, yd = self.get_extent(renderer)
ox, oy = self.get_offset()
return mtransforms.Bbox.from_bounds(ox-xd, oy-yd, w, h)
def get_extent(self, renderer):
if self._dpi_cor: # True, do correction
dpi_cor = renderer.points_to_pixels(1.)
else:
dpi_cor = 1.
zoom = self.get_zoom()
data = self.get_data()
ny, nx = data.shape[:2]
w, h = nx*zoom, ny*zoom
return w, h, 0, 0
def draw(self, renderer):
#.........这里部分代码省略.........
示例13: ScalarFormatter
heights = np.random.random(years.shape) * 7000 + 3000
fmt = ScalarFormatter(useOffset=False)
ax.xaxis.set_major_formatter(fmt)
for year, h, bc in zip(years, heights, box_colors):
bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h)
bbox = TransformedBbox(bbox0, ax.transData)
rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic")
ax.add_artist(rb_patch)
ax.annotate(r"%d" % (int(h/100.)*100),
(year, h), va="bottom", ha="center")
patch_gradient = BboxImage(ax.bbox,
interpolation="bicubic",
zorder=0.1,
)
gradient = np.zeros((2, 2, 4), dtype=np.float)
gradient[:, :, :3] = [1, 1, 0.]
gradient[:, :, 3] = [[0.1, 0.3], [0.3, 0.5]] # alpha channel
patch_gradient.set_array(gradient)
ax.add_artist(patch_gradient)
ax.set_xlim(years[0]-0.5, years[-1]+0.5)
ax.set_ylim(0, 10000)
fig.savefig('ribbon_box.png')
plt.show()
示例14: pltshow
else:
def pltshow(mplpyplot):
mplpyplot.show()
# nodebox section end
if 1: # __name__ == "__main__":
fig = plt.figure(1)
ax = plt.subplot(121)
txt = ax.text(0.5, 0.5, "test", size=30, ha="center", color="w")
kwargs = dict()
bbox_image = BboxImage(txt.get_window_extent,
norm=None,
origin=None,
clip_on=False,
**kwargs
)
a = np.arange(256).reshape(1, 256)/256.
bbox_image.set_data(a)
ax.add_artist(bbox_image)
ax = plt.subplot(122)
a = np.linspace(0, 1, 256).reshape(1, -1)
a = np.vstack((a, a))
maps = sorted(
m for m in plt.cm.cmap_d
if not m.endswith("_r") and # Skip reversed colormaps.
not m.startswith(('spectral', 'Vega')) # Skip deprecated colormaps.
)
示例15: plothist
def plothist(ax= None,
xdata= np.arange(4, 9),
ydata= np.random.random(5),
labels= [],
colors = 'random',
figName='redunca03'):
if len(xdata) != len(ydata):
raise StandardError('xdata and ydata must have the same len()')
try:
IMAGESPATH= os.path.join(wx.GetApp().installDir, 'nicePlot','images')
except:
path1= sys.argv[0]
if os.path.isfile(path1):
path1= os.path.split(path1)[0]
path1= path1.decode( sys.getfilesystemencoding())
if os.path.split( path1)[-1] == 'nicePlot':
IMAGESPATH= os.path.join( path1, 'images')
else:
IMAGESPATH= os.path.join( path1, 'nicePlot', 'images')
# se generan los colores en forma aleatoria
box_colors = _generatecolors( colors,len( xdata))
# se genera la figura
fig = plt.gcf()
if ax == None:
ax = plt.gca()
fmt = ScalarFormatter( useOffset=False)
ax.xaxis.set_major_formatter( fmt)
for year, h, bc in zip( xdata, ydata, box_colors):
bbox0 = Bbox.from_extents(year-0.5, 0.0, year+0.5, h) # year-0.48, 0., year+0.48, year-1 year+1
bbox = TransformedBbox(bbox0, ax.transData)
rb_patch = _RibbonBoxImage(bbox, bc, figName,
path= os.path.join(IMAGESPATH, 'histplot'),
interpolation="bicubic")
ax.add_artist(rb_patch)
if 0:
if type(h) == type(1):
ax.annotate(r"%d" % h,
(year, h), va="bottom", ha="center")
elif type(h) == type(1.1):
ax.annotate(r"%f" % h,
(year, h), va="bottom", ha="center")
elif str(type(h)) == "<type 'numpy.int32'>":
ax.annotate(r"%d" % h,
(year, h), va="bottom", ha="center")
patch_gradient = BboxImage( ax.bbox,
interpolation="bicubic",
zorder=0.1,
)
gradient = np.zeros( (2, 2, 4), dtype=np.float)
gradient[:,:,:3] = [1, 1, 1]
gradient[:,:,3] = [[0.2, 0.3],[0.2, 0.5]] # alpha channel
patch_gradient.set_array( gradient)
ax.add_artist( patch_gradient)
ax.set_xlim( xdata[0]-1.0, xdata[-1]+1.0)
# se determinan los limites para el eje Y
try:
ydatamax = ydata.max() # en el caso de informacion proveniente de numpy
except AttributeError:
ydatamax = max(ydata)
if ydatamax > 0.0:
maxYlimit = ydatamax*1.05
elif ydatamax == 0.0:
maxYlimit = 1.0
else:
maxYlimit = ydatamax*(1.0-0.05)
ax.set_ylim( 0, maxYlimit)
return ( fig,plt)