本文整理汇总了Python中matplotlib.image.BboxImage.set_data方法的典型用法代码示例。如果您正苦于以下问题:Python BboxImage.set_data方法的具体用法?Python BboxImage.set_data怎么用?Python BboxImage.set_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.image.BboxImage
的用法示例。
在下文中一共展示了BboxImage.set_data方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: imagesAtPositions
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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: test_bbox_image_inverted
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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)
示例4: test_bbox_image_inverted
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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)
示例5: imagesAsTickMarks
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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)
示例6: plot_wind_data2
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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'}
)
示例7: imread
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
# 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()
示例8: OffsetImage
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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):
#.........这里部分代码省略.........
示例9: dict
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
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.
)
# fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
ncol = 2
示例10: BboxImage
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
# 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)
## third
#lowC2 = plt.gca().transData.transform((lowPos[0]+6.5,lowPos[1]))
#upC2 = plt.gca().transData.transform((upPos[0]+6.5,upPos[1]))
示例11: Bbox
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.image import BboxImage
from matplotlib.transforms import Bbox, TransformedBbox
img = np.random.randint(0, 255, (100, 200, 3))
print img.shape
ax = plt.subplot()
loc = np.array([[0, 0], [200.0, 100.0]])
bbox0 = Bbox(loc)
bbox = TransformedBbox(bbox0, ax.transData)
bbox_image = BboxImage(bbox)
bbox_image.set_data(img)
ax.add_artist(bbox_image)
bbox_image.bbox._bbox.set_points(loc + [10, 5])
bbox_image.bbox.invalidate()
ax.set_xlim(-10, 210)
ax.set_ylim(-10, 110)
ax.axis("off")
plt.show()
示例12: BboxImage
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
ax.add_patch(patches.Rectangle((8-.1,TICKYPOS-.05),.2,.2,
fill=False,clip_on=False))
ticks = [0,2,4,6,8]
a = []
for i in ticks[:2]:
lowerCorner = ax.transData.transform(((i+1-.225),TICKYPOS-.225))
# lowerCorner = ax.transData.transform((0.775,TICKYPOS-.225))
upperCorner = ax.transData.transform(((i+1+.225),TICKYPOS+.225))
# upperCorner = ax.transData.transform((1.225,TICKYPOS+.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/%s.png' % names[i]))
a.append(bbox_image)
ax.add_artist(bbox_image)
plt.xticks(_rl(a), a)
plt.show()
示例13: plotDif_ind
# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_data [as 别名]
def plotDif_ind(leap, est, tMag, setName):
dif = leap - est
normed = np.linalg.norm(dif, axis=1)
mean = np.mean(normed)
std = np.var(normed) ** 2
# mean = np.mean(dif,axis=0)
# std = np.var(dif, axis=0)**2
print "mean: %s +- %s" % (mean, std)
##Direct input
plt.rcParams["text.latex.preamble"] = [r"\usepackage{lmodern}"]
# Options
params = {
"text.usetex": True,
"font.size": 11,
"font.family": "lmodern",
"text.latex.unicode": True
# 'figure.autolayout': True
}
plt.rcParams.update(params)
#
figHeight = 5
figWidth = 6
#
fig = plt.figure(figsize=(figWidth, figHeight), dpi=300)
# plt.figure()
ax = fig.add_axes([0, 0, figWidth, figHeight], frameon=False)
# ax = fig.set_axis_off()
styleL = ["solid", "dashed", "dotted", "dashdot"]
if len(est[0]) == 3:
leap = leap[:, :-1]
fMCP = plt.subplot(411)
fMCP.plot(tMag, leap[:, 0], c="r", ls=styleL[0])
fMCP.plot(tMag, est[:, 0], c="g", ls=styleL[0])
fMCP.set_ylabel(r"$\theta_{MCP}$ [rad]")
plt.setp(fMCP.get_xticklabels(), visible=False)
fPIP = plt.subplot(412, sharey=fMCP, sharex=fMCP)
fPIP.plot(tMag, leap[:, 1], c="r", ls=styleL[0])
fPIP.plot(tMag, est[:, 1], c="g", ls=styleL[0])
fPIP.plot(tMag, leap[:, 2], c="r", ls=styleL[1])
fPIP.plot(tMag, est[:, 2], c="g", ls=styleL[1])
fPIP.set_ylabel(r"$\theta_{PIP}$\\ \, $\theta_{DIP}$ [rad]")
plt.setp(fPIP.get_xticklabels(), visible=False)
aMCP = plt.subplot(413, sharey=fMCP, sharex=fMCP)
aMCP.plot(tMag, leap[:, 3], c="r", ls=styleL[0])
aMCP.plot(tMag, est[:, 3], c="g", ls=styleL[0])
aMCP.set_ylabel(r"$\phi_{MCP}$ [rad]")
plt.setp(aMCP.get_xticklabels(), visible=True)
fMCP.set_title("Difference " + setName)
difP = plt.subplot(414, sharey=fMCP, sharex=fMCP)
dif = leap - est
normedDif = np.linalg.norm(dif, axis=1)
difP.plot(tMag, normedDif, c="k", ls="-")
difP.set_ylabel("Normed\nDifference [rad]")
difP.set_xlabel("Time [sec]")
difP.set
plt.xlim([0, tMag[-1] + 1])
plt.xticks(np.arange(0, tMag[-1], 5))
linePerf = mlines.Line2D([], [], color="r", markersize=15, label="Leap")
lineEst = mlines.Line2D([], [], color="g", markersize=15, label="Estimated")
plt.figlegend((linePerf, lineEst), ("Leap", "Estimated"), loc="upper center")
# plt.figlegend((linePerf,lineEst),
# ('Leap','Estimated'), loc='upper center', bbox_to_anchor=(0.5,1.04), ncol=2)
""" adding the pictures... """
TICKYPOS = -0.75
difP.get_xaxis().set_ticklabels([])
# lowerCorner = difP.transData.transform((.8,TICKYPOS-.2))
# upperCorner = difP.transData.transform((1.2,TICKYPOS+.2))
lowPos = [-1.6, TICKYPOS - 1.2]
upPos = [lowPos[0] + 6, lowPos[1] + 1.5]
print lowPos
print upPos
lowerCorner = difP.transData.transform((lowPos[0], lowPos[1]))
upperCorner = difP.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/bestLeap/out-0.jpg"))
difP.add_artist(bbox_image0)
#.........这里部分代码省略.........