Contour diagram for Pandas and/or Seaborn for a 3-column matrix - pandas

I have like 400 data points which are in forms of a 3-tuple. Something like this:
[[1.2, 3.4, 7.8],
[3.1, 2.6, 3.4],
...
]
Each row is a 3-tuple point, (x, y, z) which shows a point in 3D space.
What I want to do is drawing a contour diagram using these values in the form shown in https://en.wikipedia.org/wiki/Contour_line.
I want this:https://en.wikipedia.org/wiki/Contour_line#/media/File:Contour2D.svg.
I want the third dimension (z) to be the source for contours.
I have seen some other examples on the net, but they are so confusing. They are relying on a function to draw the diagram which is not in my case. I am representing the function as a matrix.
I hope I give enough information to let you know what I am looking for.
Thanks guys.

You can try conrec algorithm from Paul Bourke. It's implemented in many languages and also good explained. It uses the marching cube algorithm.

Related

How to do polynomial transformations programmatically?

Suppose i have bunches of the below n=36 polynomials/data:
They are all quite similar but with sightly different roof and amplitude, what is the best approach for me to code a sequence of coefficients/changes so that i can use this sequence to transform one polynomial to another one, say: the blue one + a change sequence -> the green one?
P.S.:
I had tried to use gaussian curve to fit the data, but unfortunately the results were very poor, so i have to use polynomials;
Currently the data are fitted by numpy.polyfit(x, y, 35)
Edit:
The intention is to find a way to generically describe the transformation between two polys, so i can use it to transform the future polys, say: in future i get a totally new poly like above, i can use this transformation code to transform it in a specific manner: increase/decrease the roof/amplitude, by specific manner i mean, note in the graph, the y changes around the roof x is always bigger, along +x / -x the changes are descending in a way, quite like gaussian curve, but unfortunately cannot use gaussian curve to express the data

Camera matrix from essential matrix

I am trying to extract camera matrix from essential matrix. I found some answers about this.
determine camera rotation and translation matrix from essential matrix
Rotation and Translation from Essential Matrix incorrect
In these answers, they suggest me to use newE where [U,S,V] = svd(E) and newE = U*diag(1,1,0)*Vt. I don't understand why I need to use newE. As I know, singular values are unique. So changing singular values to diag(1,1,0) seems to make E to completely different values.
I read 'Multiple View Geometry in Computer Vision' also, but it just refers to the ideal case, i.e., singular values are (1,1,0). I didn't find the reason of using newE.
Please can anyone explain me why people use newE?
If I understand your question correctly, then since you source data (and thus E) is usually noisy real world data, then by using diag(1,1,0) you are constraining the matrix to be of the correct scale and rank and algebraically enforcing the geometric constraints.
Wikipedia also a has a nice section explaining this.

How can I plot this kind of picture using Matplotlib or Mayavi?

I have three 2d arrays: X,Y,Z, which contain irregular 3d points coordinate,respectively.And another 2d array data, which contains the values on those points.
What I want to do is to display this data in 3d space , with 0 value part masked out.Much like this one:
In matlab, I can use function fill3 to achieve this, but how can I plot the same kind of picture in matplotlib or mayavi ? I have tried to use mask array ,plot_surface and colorface together, as the example here:
Plotting a masked surface plot using python, numpy and matplotlib
and it worked, the result is the link below:
but that is really really slow, and will cost too much time. Is there a better way?
Well, today I find out an alternative way to solve the problem. Except using plot_surface, I choose to use scatter3D,
the core code is some what like this
aa=np.shape(X)[0]
bb=np.shape(X)[1]
x=X.reshape(aa*bb)
y=Y.reshape(aa*bb)
z=Z.reshape(aa*bb)
data=data.reshape(aa*bb)
x1=[]
y1=[]
z1=[]
da1=[]
for i in range(aa*bb):
if data[i]>0:
x1.append(x[i])
y1.append(y[i])
z1.append(z[i])
da1.append(data[i])
my_cmap=cm.jet
my_cmap.set_over('c')
my_cmap.set_under('m')
N=da1/max(da1)
fig=plt.figure()
ax=fig.add_subplot(111,projection='3d')
ax.scatter3D(x1,y1,z1,s=6,alpha=0.8,marker=',',facecolors=my_cmap(N),lw=0)
and the result is like this:
this doesn't really solve the problem, but it is a nice substitution.
I'll keep waiting for more answers.

Least Squared constrained for Rototranslation

I want to detect the best rototraslation matrix between two set of points.
The second set of points is the same of the first, but rotated, traslated and affecteb by noise.
I tried to use least squared method by obviously the solution is usually similar to a rotation matrix, but with incompatible structure (for example, where i should get a value that represents the cosine of an angle i could get a value >1).
I've searched for the Constrained Least Squared method but it seems to me that the constrains of a rototraslation matrix cannot be expressed in this form.
In this PDF i've stated the problem more formally:
http://dl.dropbox.com/u/3185608/minquad_en.pdf
Thank you for the help.
The short answer: What you will need here is "Principal Component Analysis".
Apply this to both sets of points centered at their respective centers of mass. The PCA will effectively give you a rotation matrix for each aligned to the data set principal components. Multiplying the inverse matrix of the original set by the new rotation will give you a matrix that takes the old (centered) set to the new. Inverse translations and translations can similarly be applied to the rotation to create a homogeneous matrix that maps the one set to the other.
The book PRINCE, Simon JD. Computer vision: models, learning, and inference. Cambridge University Press, 2012.
gives, in Appendix "B.4 Reparameterization", some info about how to constrain a matrix to be a rotation matrix.
It seems to me that your problem has also a solution based on SVD: see the Kabsch algorithm also described by Olga Sorkine-Hornung and Michael Rabinovich in
Least-Squares Rigid Motion Using SVD and, more practically, by Nghia Kien Ho in FINDING OPTIMAL ROTATION AND TRANSLATION BETWEEN CORRESPONDING 3D POINTS.

Easiest way to plot values as symbols in scatter plot?

In an answer to an earlier question of mine regarding fixing the colorspace for scatter images of 4D data, Tom10 suggested plotting values as symbols in order to double-check my data. An excellent idea. I've run some similar demos in the past, but I can't for the life of me find the demo I remember being quite simple.
So, what's the easiest way to plot numerical values as the symbol in a scatter plot instead of 'o' for example? Tom10 suggested plt.txt(x,y,value)- and that is the implementation used in a number of examples. I however wonder if there's an easy way to evaluate "value" from my array of numbers? Can one simply say: str(valuearray) ?
Do you need a loop to evaluate the values for plotting as suggested in the matplotlib demo section for 3D text scatter plots?
Their example produces:
(source: sourceforge.net)
However, they're doing something fairly complex in evaluating the locations as well as changing text direction based on data. So, is there a cute way to plot x,y,C data (where C is a value often taken as the color in the plot data- but instead I wish to make the symbol)?
Again, I think we have a fair answer to this- I just wonder if there's an easier way?
The easiest way I've seen to do this is:
for x, y, val in zip(x_array, y_array, val_array):
plt.text(x, y, val)
Also, btw, you suggested using str(valarray), and this, as you may have noticed doesn't work. To convert an array of numbers to a sequence of strings you could use
valarray.astype(str)
to get a numpy array, or,
[str(v) for v in valarray]
to get a Python list. But even with valarray as a proper sequence of strings, plt.text won't iterate over it's inputs.