in c3dm/tools/vis_utils.py [0:0]
def show_projections( viz,
env,
p,
v=None,
image_path=None,
image=None,
title='projs',
cmap__='gist_ncar',
markersize=None,
sticks=None,
stickwidth=2,
stick_color=None,
plot_point_order=False,
bbox = None,
win=None ):
if image is None:
try:
im = Image.open(image_path).convert('RGB')
im = np.array(im).transpose(2,0,1)
except:
im = None
print('!cant load image %s' % image_path)
else:
im = image
nkp = int(p.shape[2])
pid = np.linspace(0.,1.,nkp);
if v is not None:
okp = np.where(v > 0)[0]
else:
okp = np.where(np.ones(nkp))[0]
possible_markers = ['.','*','+']
markers = [possible_markers[i%len(possible_markers)] for i in range(len(p))]
if markersize is None:
msz = 50
if nkp > 40:
msz = 5
markersizes = [msz]*nkp
else:
markersizes = [markersize]*nkp
fig = plt.figure(figsize=[11,11])
if im is not None:
plt.imshow( im.transpose( (1,2,0) ) ); plt.axis('off')
if sticks is not None:
if stick_color is not None:
linecol = stick_color
else:
linecol = [0.,0.,0.]
for p_ in p:
for stick in sticks:
if v is not None:
if v[stick[0]]>0 and v[stick[1]]>0:
linestyle='-'
else:
continue
plt.plot( p_[0,stick], p_[1,stick], linestyle,
color=linecol, linewidth=stickwidth, zorder=1 )
for p_, marker, msz in zip(p, markers, markersizes):
plt.scatter( p_[0,okp], p_[1,okp], msz, pid[okp],
cmap=cmap__, linewidths=2, marker=marker, zorder=2, \
vmin=0., vmax=1. )
if plot_point_order:
for ii in okp:
plt.text( p_[0,ii], p_[1,ii], '%d' % ii, fontsize=int(msz*0.25) )
if bbox is not None:
import matplotlib.patches as patches
# Create a Rectangle patch
rect = patches.Rectangle((bbox[0],bbox[1]),bbox[2],bbox[3],\
linewidth=1,edgecolor='r',facecolor='none')
plt.gca().add_patch(rect)
if im is None:
plt.gca().invert_yaxis()
plt.axis('equal')
plt.gca().axes.get_xaxis().set_visible(False)
plt.gca().axes.get_yaxis().set_visible(False)
# plt.gca().set_frame_on(False)
plt.gca().set_axis_off()
else: # remove all margins
# plt.gca().axes.get_xaxis().set_visible(False)
# plt.gca().axes.get_yaxis().set_visible(False)
# plt.gca().set_frame_on(False)
# plt.gca().set_axis_off()
pass
# return fig
improj = np.array(fig2data(fig))
if env is not None:
win = viz.image( np.array(improj).transpose(2,0,1), \
env=env, opts={ 'title': title }, win=win )
else:
win = None
plt.close(fig)
return improj, win