python - pylab scatter plot appears transposed -
i have been playing various interpolation techniques - , particularly varieties shown in youtube video https://www.youtube.com/watch?v=_cjlvhdj0j4
however, scatter module plots points in wrong location. have transposed them below (example 5) make work, not work if area of interest not centred on origin (test_rbf).
am mis-understanding fundamental, or problem in pylab scatter module?
# example 5 # # https://www.youtube.com/watch?v=_cjlvhdj0j4 import numpy np scipy import interpolate import pylab py def func(x,y): return (x+y)*np.cos(-5.0*x + 4.0*y) x = np.random.uniform(-1.0, 1.0,size=50) y = np.random.uniform(-1.0, 1.0,size=50) fvals = func(x,y) newfunc = interpolate.rbf(x, y, fvals, function='multiquadric') xnew, ynew = np.mgrid[-1:1:100j, -1:1:100j] fnew = newfunc(xnew, ynew) true = func(xnew, ynew) py.figure() py.clf() py.imshow( fnew, extent=[-1,1,-1,1], cmap=py.cm.jet) # py.scatter( x, y, 30, fvals, cmap=py.cm.jet) py.scatter( y, -x, 30, fvals, cmap=py.cm.jet) py.show() enthought.mayavi import mlab mlab.clf() mlab.surf(xnew, ynew, fnew*2)
if use
ynew, xnew = np.mgrid[-1:1:100j, -2:2:100j]
instead of
xnew, ynew = np.mgrid[-1:1:100j, -2:2:100j]
then xnew
vary move across columns, , ynew
vary move down rows. (i changed x-range [-1,1] [-2,2] make clear numbers control range.)
combine @hitzg's suggestion add origin='lower'
call imshow
, , get:
import numpy np scipy import interpolate import matplotlib.pyplot plt np.random.seed(2015) def func(x,y): return (x+y)*np.cos(-5.0*x + 4.0*y) x = np.random.uniform(-2.0, 2.0, size=50) y = np.random.uniform(-1.0, 1.0, size=50) fvals = func(x,y) newfunc = interpolate.rbf(x, y, fvals, function='multiquadric') ynew, xnew = np.mgrid[-1:1:100j, -2:2:100j] fnew = newfunc(xnew, ynew) plt.figure() plt.imshow(fnew, extent=[-2,2,-1,1], cmap=plt.cm.jet, origin='lower') plt.scatter(x, y, s=30, c=fvals, cmap=plt.cm.jet) plt.show()
Comments
Post a Comment