本文整理汇总了Python中matplotlib.cbook.get_sample_data函数的典型用法代码示例。如果您正苦于以下问题:Python get_sample_data函数的具体用法?Python get_sample_data怎么用?Python get_sample_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_sample_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
def show(location_summaries, ap_names, ap_macs):
datafile = cbook.get_sample_data('C:/Dev/android/WifiRecord/app/src/main/res/drawable/greenstone_lower.png')
lower_img = imread(datafile)
lower_img_flip = lower_img[::-1, :, :]
lower_img_faded = (255*0.7 + lower_img_flip*0.3).astype('uint8')
datafile = cbook.get_sample_data('C:/Dev/android/WifiRecord/app/src/main/res/drawable/greenstone_upper.png')
upper_img = imread(datafile)
upper_img_flip = upper_img[::-1, :, :]
upper_img_faded = (255*0.7 + upper_img_flip*0.3).astype('uint8')
fig, (ax_upper, ax_lower) = plt.subplots(2, 1)
#mng = plt.get_current_fig_manager()
#mng.full_screen_toggle()
for (num, name) in ap_names.iteritems():
# if num>=1:
# break
ax_upper.cla()
ax_upper.imshow(upper_img_faded, zorder=0, extent=[0, 2200, 0, 1054])
ax_upper.set_xlim(400, 1800)
ax_upper.set_ylim(800, 400)
ax_lower.cla()
ax_lower.imshow(lower_img_faded, zorder=0, extent=[0, 2200, 0, 760])
ax_lower.axis([300, 1000, 100, 500])
ax_lower.set_ylim(500, 100)
add_points(ax_upper, ax_lower, num, name, location_summaries)
plt.draw()
time.sleep(0.25)
示例2: showImage
def showImage(ax,
filename,
title='',
label='',
label_color='black',
fontsize=DEFAULT_FONTSIZE,
rotate=False,
label_position=(0.05,0.95),
dpi=None,
):
from matplotlib import pyplot as plt
import matplotlib.cbook as cbook
setLabel(ax,
label,
color=label_color,
fontsize=fontsize,
position=label_position,
dpi=dpi,
)
image_file = cbook.get_sample_data(abspath(filename))
image = plt.imread(image_file)
if rotate:
image = np.transpose(image, (1,0,2))
im = ax.imshow(image)
ax.axis('off')
ax.set_title(title, fontsize=fontsize)
return im
示例3: __display_image__
def __display_image__(self,subject_id,args_l,kwargs_l,block=True,title=None):
"""
return the file names for all the images associated with a given subject_id
also download them if necessary
:param subject_id:
:return:
"""
subject = self.subject_collection.find_one({"zooniverse_id": subject_id})
url = subject["location"]["standard"]
slash_index = url.rfind("/")
object_id = url[slash_index+1:]
if not(os.path.isfile(self.base_directory+"/Databases/"+self.project+"/images/"+object_id)):
urllib.urlretrieve(url, self.base_directory+"/Databases/"+self.project+"/images/"+object_id)
fname = self.base_directory+"/Databases/"+self.project+"/images/"+object_id
image_file = cbook.get_sample_data(fname)
image = plt.imread(image_file)
fig, ax = plt.subplots()
im = ax.imshow(image,cmap = cm.Greys_r)
for args,kwargs in zip(args_l,kwargs_l):
print args,kwargs
ax.plot(*args,**kwargs)
if title is not None:
ax.set_title(title)
plt.show(block=block)
示例4: get_demo_image
def get_demo_image():
import numpy as np
from matplotlib.cbook import get_sample_data
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
z = np.load(f)
# z is a numpy array of 15x15
return z, (-3, 4, -4, 3)
示例5: Scatter
def Scatter():
"""
Demo of scatter plot with varying marker colors and sizes.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
# Load a numpy record array from yahoo csv data with fields date,
# open, close, volume, adj_close from the mpl-data/example directory.
# The record array stores python datetime.date as an object array in
# the date column
datafile = cbook.get_sample_data('goog.npy')
price_data = np.load(datafile).view(np.recarray)
price_data = price_data[-250:] # get the most recent 250 trading days
delta1 = np.diff(price_data.adj_close)/price_data.adj_close[:-1]
# Marker size in units of points^2
volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2
close = 0.003 * price_data.close[:-2] / 0.003 * price_data.open[:-2]
fig, ax = plt.subplots()
ax.scatter(delta1[:-1], delta1[1:], c=close, s=volume, alpha=0.5)
ax.set_xlabel(r'$\Delta_i$', fontsize=20)
ax.set_ylabel(r'$\Delta_{i+1}$', fontsize=20)
ax.set_title('Volume and percent change')
ax.grid(True)
fig.tight_layout()
plt.show()
示例6: mapPerPeriod
def mapPerPeriod(aodperDegree, lats, longs, title, savefile, cmapname,minv=0,maxv=0):
# Make plot with vertical (default) colorbar
fig, ax = plt.subplots()
data = aodperDegree
datafile = cbook.get_sample_data('C:/Users/alex/marspython/aerosol/gr.png')
img = imread(datafile)
ax.imshow(img, zorder=1, alpha=0.3,
extent=[float(min(longs))-0.5, float(max(longs))+0.5, float(min(lats)) - 0.5, float(max(lats))+0.5])
if minv<>0 or maxv<>0 :
cax = ax.imshow(data, zorder=0, interpolation='spline16', cmap=cm.get_cmap(cmapname),
extent=[float(min(longs)), float(max(longs)), float(min(lats)), float(max(lats))],
vmin=minv,vmax=maxv)
else:
cax = ax.imshow(data, zorder=0, interpolation='spline16', cmap=cm.get_cmap(cmapname),
extent=[float(min(longs)), float(max(longs)), float(min(lats)), float(max(lats))])
ax.set_title(title)
# Add colorbar, make sure to specify tick locations to match desired ticklabels
#cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
cbar = fig.colorbar(cax)
#cbar.ax.set_yticklabels(['< -1', '0', '> 1']) # vertically oriented colorbar
pylab.savefig(savefile + ".png")
示例7: __plot__
def __plot__(self,fname):
image_file = cbook.get_sample_data(fname)
image = plt.imread(image_file)
fig, ax1 = plt.subplots(1, 1)
fig.set_size_inches(52,78)
ax1.imshow(image)
horiz_segments,vert_segments,horiz_intercepts,vert_intercepts = self.__get_grid_segments__()
h_lines = self.__segments_to_grids__(horiz_segments,horiz_intercepts,horiz=True)
v_lines = self.__segments_to_grids__(vert_segments,vert_intercepts,horiz=False)
for (lb,ub) in h_lines:
X,Y = zip(*lb)
ax1.plot(X, Y,color="blue")
X,Y = zip(*ub)
ax1.plot(X, Y,color="blue")
for (lb,ub) in v_lines:
X,Y = zip(*lb)
ax1.plot(X, Y,color="blue")
X,Y = zip(*ub)
ax1.plot(X, Y,color="blue")
plt.savefig("/home/ggdhines/Databases/temp.jpg",bbox_inches='tight', pad_inches=0,dpi=72)
示例8: use_image
def use_image(self, axis, image_path):
image_path = toolbox_basic.check_path(image_path)
datafile = cbook.get_sample_data(image_path)
image = Image.open(datafile)
axis.set_ylim(0,image.size[0])
axis.set_ylim(image.size[1],0)
return imshow(image)
示例9: test_equalize
def test_equalize(data):
'''Test'''
dfile = cbook.get_sample_data('s1045.ima', asfileobj=False)
im = np.fromstring(file(dfile, 'rb').read(), np.uint16).astype(float)
im.shape = 256, 256
#imshow(im, ColormapJet(256))
#imshow(im, cmap=cm.jet)
imvals = np.sort(im.flatten())
lo = imvals[0]
hi = imvals[-1]
steps = (imvals[::len(imvals)/256] - lo) / (hi - lo)
num_steps = float(len(steps))
interps = [(s, idx/num_steps, idx/num_steps) for idx, s in enumerate(steps)]
interps.append((1, 1, 1))
cdict = {'red' : interps,
'green' : interps,
'blue' : interps}
histeq_cmap = colors.LinearSegmentedColormap('HistEq', cdict)
pylab.figure()
pylab.imshow(im, cmap=histeq_cmap)
pylab.title('histeq')
pylab.show()
示例10: draw_map_image
def draw_map_image(x,y):
f2,ax=plt.subplots()
image_file = cbook.get_sample_data('/mnt/hgfs/I/ComputerVision/ISCAS/housemap001.jpg')
img = plt.imread(image_file)
#img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
#img=img[:,:,0]
ax.set_xticks([])
ax.set_yticks([])
plt.title('emotion map')
# Show the image
plt.imshow(img)
# matplotColors=['blue','green','red','cyan','magenta','yellow','black','white']
colors = ['red', 'blue', 'yellow', 'green', 'cyan', 'black', 'magenta']
assert len(colors) == emotions_num
# Now, loop through coord arrays, and create a circle at each x,y pair
for xx,yy in zip(x,y):
emotion = np.random.choice(np.arange(emotions_num), p=[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.4])
p = Circle((xx, yy), 5, color=colors[emotion])
ax.add_patch(p)
# draw legend
patches=[]
for color,label in zip(colors,y_ticks):
patch=Circle(color=color,label=label,xy=(5,5))
patches.append(patch)
plt.legend(handles=patches)
#f2.draw
#f2.canvas.draw()
return f2
示例11: paste_image
def paste_image(filename):
# annotate plot and paste image
fig, ax = plt.subplots()
xy = (0.5, 0.7)
ax.plot(xy[0], xy[1], ".r")
fn = get_sample_data(filename, asfileobj=False)
arr_lena = read_png(fn)
imagebox = OffsetImage(arr_lena, zoom=0.2)
ab = AnnotationBbox(imagebox, xy,
xybox=(120., -80.),
xycoords='data',
boxcoords="offset points",
pad=0.5,
arrowprops=dict(arrowstyle="->", connectionstyle="angle,angleA=0,angleB=90,rad=3")
)
ax.add_artist(ab)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
plt.draw()
plt.show()
示例12: __init__
def __init__(self, ax, n):
self.ax = ax
dir=os.path.abspath(os.path.dirname(sys.argv[0]))
ax.axis([0,1,0,1])
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_frame_on=True
ax.plot( [ 0.1, 0.2], [0.96, 0.96], color='blue', linewidth=2 )
ax.plot( [ 0.1, 0.2], [0.91, 0.91], color='green', linewidth=2 )
ax.plot( [ 0.1, 0.2], [0.86, 0.86], color='red', linewidth=1 )
self.text1 = ax.text( 0.3, self.ypos(2), '%d' % n )
fn = get_sample_data("%s/coolr-logo-poweredby-48.png" % dir, asfileobj=False)
arr = read_png(fn)
imagebox = OffsetImage(arr, zoom=0.4)
ab = AnnotationBbox(imagebox, (0, 0),
xybox=(.75, .12),
xycoords='data',
boxcoords="axes fraction",
pad=0.5)
ax.add_artist(ab)
示例13: show
def show(all_points_list):
datafile = cbook.get_sample_data('C:/Dev/android/WifiRecord/app/src/main/res/drawable/greenstone_lower.png')
lower_img = imread(datafile)
lower_img_flip = lower_img[::-1, :, :]
lower_img_faded = (255*0.7 + lower_img_flip*0.3).astype('uint8')
datafile = cbook.get_sample_data('C:/Dev/android/WifiRecord/app/src/main/res/drawable/greenstone_upper.png')
upper_img = imread(datafile)
upper_img_flip = upper_img[::-1, :, :]
upper_img_faded = (255*0.7 + upper_img_flip*0.3).astype('uint8')
fig, (ax_upper, ax_lower) = plt.subplots(2, 1)
#fig = fig = plt.gcf()
#(ax_upper, ax_lower) = fig.axes
#mng = plt.get_current_fig_manager()
#mng.full_screen_toggle()
for (i, points) in enumerate(zip(*all_points_list)):
ax_upper.cla()
ax_upper.imshow(upper_img_faded, zorder=0, extent=[0, 2200, 0, 1054])
ax_upper.set_xlim(400, 1800)
ax_upper.set_ylim(800, 300)
#ax_upper.set_xlim(1000, 1850)
#ax_upper.set_ylim(750, 450)
ax_lower.cla()
ax_lower.imshow(lower_img_faded, zorder=0, extent=[0, 2200, 0, 760])
ax_lower.axis([300, 1000, 100, 500])
ax_lower.set_ylim(500, 100)
colors = ("Black", "Red", "Blue", "Yellow")
for (j, point) in enumerate(points):
x = point["x"]
y = point["y"]
display = str(i) + "," + "{:.1f}".format(point["score"])
if point["level"]==0:
ax_lower.plot([x], [y], 'o', color = colors[j])
ax_lower.text(x+1, y, display, fontsize=8)
else:
ax_upper.plot([x], [y], 'o', color = colors[j])
ax_upper.text(x+1, y, display, fontsize=8)
plt.draw()
time.sleep(0.1)
plt.show()
示例14: main
def main():
landmarks = ['American Museum of Natural History',
'Brooklyn Bridge',
'Central Park',
'Guggenheim Museum',
'High Line',
'Rockefeller Center',
'September 11 Memorial',
'Statue of Liberty',
'Times Square',
'Mystery']
dist = distanceMatrix()
adist = np.array(dist)
amax = np.amax(dist)
adist /= amax
mds = manifold.MDS(n_components=2, dissimilarity="precomputed", random_state=6)
results = mds.fit(dist)
coords = results.embedding_
print coords
print coords[:,1][0]
for x in range (len(coords[:,1])):
coords[:,1][x] = coords[:,1][x]*-1
#Can comment this out to run without background NYC MAP
datafile = cbook.get_sample_data('/Users/niqson/5map.png')
img = imread(datafile)
plt.scatter(
coords[:, 0], coords[:, 1], marker = 'o',s=25,color='cyan'
)
plt.annotate('Museum of Nat. History', coords[0])
plt.annotate('Brooklyn Bridge', coords[1])
plt.annotate('Central Park', coords[2],xytext = (-20, 20),textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.2', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
plt.annotate('Guggenheim Museum', coords[3],xytext = (20, 10),textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.2', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
plt.annotate('High Line', coords[4],xytext = (-20, 20),textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.2', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
plt.annotate('Rockefeller Center', coords[5])
plt.annotate('9/11 Memorial', coords[6])
plt.annotate('Statue of Liberty', coords[7])
plt.annotate('Times Square', coords[8],xytext = (-20, 20),textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.2', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
plt.annotate('Mystery', coords[9],size = 20)
rotated_img = scipy.ndimage.rotate(img, -10)
plt.imshow(rotated_img, zorder=0, extent=[-32000, 30000, -30000, 19000])
plt.show()
'''
示例15: logo_box
def logo_box(self):
logo_offset_image = OffsetImage(read_png(get_sample_data(logo_location, asfileobj=False)), zoom=0.25, resample=1, dpi_cor=1)
text_box = TextArea(logo_text, textprops=dict(color='#444444', fontsize=50, weight='bold'))
logo_and_text_box = HPacker(children=[logo_offset_image, text_box], align="center", pad=0, sep=25)
anchored_box = AnchoredOffsetbox(loc=2, child=logo_and_text_box, pad=0.8, frameon=False, borderpad=0.)
return anchored_box