Skip to content

Instantly share code, notes, and snippets.

@gcr
Last active December 28, 2015 19:59
Show Gist options
  • Select an option

  • Save gcr/7553850 to your computer and use it in GitHub Desktop.

Select an option

Save gcr/7553850 to your computer and use it in GitHub Desktop.
import random
def plot_correspondence(points1, points2, fraction_of_lines):
fig,(ax1,ax2) = subplots(1,2,sharex=True,sharey=True,figsize=(10,8))
# Set plot boundaries
ax1.set_ylim(31,43)
ax1.set_xlim(-126,-112)
# Draw first points
ax1.scatter(points1[:,0],points1[:,1],s=0.5,color='b')
# Draw second points
ax2.scatter(points2[:,0],points2[:,1],s=0.5,color='r')
# Draw correspondence lines
which_lines = random.sample(xrange(len(points1)), int(fraction_of_lines*len(points1)))
for ((x1,y1),(x2,y2)) in zip(points1[which_lines], points2[which_lines]):
ax2.plot([x1, x2], [y1, y2], 'black',alpha=0.3)
return fig
# Example
points1 = np.random.randn(100,2) + np.array([-120,36])
points2 = points1+0.5*np.random.randn(100,2)
fig=plot_correspondence(points1,points2, 1)
fig.savefig("/tmp/test.png",dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment