Skip to content

Instantly share code, notes, and snippets.

@understar
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save understar/c8c60af61add3bc87617 to your computer and use it in GitHub Desktop.
Save understar/c8c60af61add3bc87617 to your computer and use it in GitHub Desktop.
plot picture scatter
# -*- coding: cp936-*-
__author__ = 'shuaiyi'
import logging
import numpy as np
import calc_tsne as tsne
import matplotlib.pyplot as plt
from features import dataset as ds
logging.getLogger().setLevel(logging.INFO)
logging.info('Loading t_SNE results.')
Xmat,LM,costs=tsne.readResult()
X=tsne.reOrder(Xmat,LM)
logging.info('Loading labels.')
labels = np.loadtxt('420_Y.txt', delimiter=',')
logging.info('Loading samples (image path).')
data_path = "E:/Classification_service/Labelsamples/labels.txt"
samples = ds(data_path)
from skimage import io
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
ax = plt.subplot(111)
logging.info('Generating picture scatter')
for i in range(len(samples.X)):
img_path = ds.getImg_path(data_path, samples.X[i][0])
logging.info('Processing %s'%img_path)
xy = (X[i,0],X[i,1])
arr_sam = io.imread(img_path)
imagebox = OffsetImage(arr_sam, zoom=0.1)
ab = AnnotationBbox(imagebox, xy,
xycoords='data',
pad=0,
)
ax.add_artist(ab)
#plt.scatter(X[:,0], X[:,1], 20, labels)
ax.grid(True)
ax.set_xlim(-60, 60)
ax.set_ylim(-60, 60)
plt.draw()
plt.show()
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
from matplotlib.cbook import get_sample_data
import numpy as np
if 1:
fig = plt.gcf()
fig.clf()
ax = plt.subplot(111)
xy = [0.3, 0.55]
arr = np.arange(100).reshape((10,10))
im = OffsetImage(arr, zoom=2)
ab = AnnotationBbox(im, xy,
xycoords='data',
pad=0.3,
)
ax.add_artist(ab)
# another image
from matplotlib._png import read_png
fn = get_sample_data("lena.png", asfileobj=False)
arr_lena = read_png(fn)
imagebox = OffsetImage(arr_lena, zoom=0.2)
xy = (0.7, 0.4)
ab = AnnotationBbox(imagebox, xy,
xycoords='data',
pad=0.5,
)
ax.add_artist(ab)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
plt.draw()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment