Skip to content

Instantly share code, notes, and snippets.

@mpilosov
Last active February 12, 2018 20:22
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 mpilosov/736438173407fc8a26488eeeb567c3b0 to your computer and use it in GitHub Desktop.
Save mpilosov/736438173407fc8a26488eeeb567c3b0 to your computer and use it in GitHub Desktop.
plotting non-functions
# something that doesn't pass the vertical line test, comes to us unordered.... we want to piecewise-interpolate.
import numpy as np
# partition our data so that each segment DOES pass the vertical line test.
c = np.where(a[:,1] >= 0.5)[0]
d = np.where(a[:,1] < 0.5)[0]
above = a[c,:] # copies of a
below = a[d,:]
print(above)
print(below)
# sort them
ab = np.argsort(above[:,0])
be = np.argsort(below[:,0])
# notice how the sorting works.
print(above[ab])
print(below[be])
plt.scatter(a[:,0], a[:,1])
plt.plot(above[ab,0], above[ab,1])
plt.plot(below[be,0], below[be,1])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment