I have a panel, 3-dimension data table. It's like a grid, just points(x,y,z).
I want to input two of them, then return the other one number, like inputting x and y, return z. But the x, y may not just exist in the grip points, so it needs to calculate by linear or any method.
In addition, I want to plot as a surface.
I googled and found the numpy.meshgrid(), I am confused how to use it. Or could you recommend any package or function could do this task?
Thank you so much !
Related
I have a polynomial function, let’s say a+bx+cx^2. I show the function in a 2d plot, but I want to progress to show it in 3d. But not just showing it, giving it height, so if I have x,y I set a Z1 which represents the first layer, and then Z2 which means the second layer, and so on,
or, giving a specific Z, which will create a higher(in height) polynomial function and then somehow connect the dots. So in the end, I will get a shape that is the 3d of that same polynomial but with height.
I don’t know how to get that done, maybe because I can't see another way to do it.
If I represent a 2d function for example:
a+bx+cx^2 function
Now if I want to view it in 3d when the current polynomial is on Z=0, how can I show it when it has height.
I want to view it like this but from 3d:
let me describe my problem, so I am creating a simple graphing calculator, the way I did it was that every y coordinate is calculated by putting it into a function f(x) then graphing the point (x, f(x)).
To make things simple for myself, whenever I wanted to shift the graph or zoom in I just adjust the dimensions of the current view and then recalculate all the new points on the screen. For example going from This to this by zooming in and shifting the screen would mean that every single point has been recalculated, for me to get the graph to look like it is formed by actual lines instead of just points I divide the width of the screen into about 1000 ~ 10000 points and plot it and if there are enough points it just looks like lines. These points are made by tuple pairs of floats.
As you could imagine there is a lot of overlap and recalculations that may be slowing down the program and so I am wondering what the best way to calculate a (x, f(x)) point, store it and anytime I change the view of the graph, if that x happens to be in view, be able to retrieve the f(x) and skip the calculation. The thing is there is going to be like thousands and thousands of these points and so I figured using list operations like "i in lst" is not efficient enough.
I am trying to make my graph as fast as possible so any suggestions would be helpful! Thanks.
I'm referencing this question and this documentation in trying to turn a set of points (the purple dots in the image below) into an interpolated grid.
As you can see, the image has missing spots where dots should be. I'd like to figure out where those are.
import numpy as np
from scipy import interpolate
CIRCLES_X = 25 # There should be 25 circles going across
CIRCLES_Y = 10 # There should be 10 circles going down
points = []
values = []
# Points range from 0-800 ish X, 0-300 ish Y
for point in points:
points.append([points.x, points.y])
values.append(1) # Not sure what this should be
grid_x, grid_y = np.mgrid[0:CIRCLES_Y, 0:CIRCLES_X]
grid = interpolate.griddata(points, values, (grid_x, grid_y), method='linear')
print(grid)
Whenever I print out the result of the grid, I get nan for all of my values.
Where am I going wrong? Is my problem even the correct use case for interpolate.grid?
First, your uncertain points are mainly at an edge, so it's actually extrapolation. Second, interpolation methods built into scipy deal with continuous functions defined on the entire plane and approximate it as a polynomial. While yours is discrete (1 or 0), somewhat periodic rather than polynomial and only defined in a discrete "grid" of points.
So you have to invent some algorithm to inter/extrapolate your specific kind of function. Whether you'll be able to reuse an existing one - from scipy or elsewhere - is up to you.
One possible way is to replace it with some function (continuous or not) defined everywhere, then calculate that approximation in the missing points - whether as one step as scipy.interpolate non-class functions do or as two separate steps.
e.g. you can use a 3-D parabola with peaks in your dots and troughs exactly between them. Or just with ones in the dots and 0's in the blanks and hope the resulting approximation in the grid's points is good enough to give a meaningful result (random overswings are likely). Then you can use scipy.interpolate.RegularGridInterpolator for both inter- and extrapolation.
or as a harmonic function - then what you're seeking is Fourier transformation
Another possible way is to go straight for a discrete solution rather than try to shoehorn the continual mathanalysis' methods into your case: design a (probably entirely custom) algorithm that'll try to figure out the "shape" and "dimensions" of your "grids of dots" and then simply fill in the blanks. I'm not sure if it is possible to add it into the scipy.interpolate's harness as a selectable algorithm in addition to the built-in ones.
And last but not the least. You didn't specify whether the "missing" points are points where the value is unknown or are actual part of the data - i.e. are incorrect data. If it's the latter, simple interpolation is not applicable at all as it assumes that all the data are strictly correct. Then it's a related but different problem: you can approximate the data but then have to somehow "throw away irregularities" (higher order of smallness entities after some point).
I have been puzzled about this issue for some time now, regarding the creation of streamplot given what I would consider limited data compared to the examples I've seen.
I am attempting to plot streamlines of particles in a flow field given the following information on each particle: x coordinate, y coordinate, x-component velocity, y-component velocity. Each of these data sets is in the form of a one-dimensional array. Based on the documentation of the streamplot function in matplotlib, the first two input arguments should be one-dimensional arrays, and the third and fourth should be two-dimensional.
So, my question is: what is the most accurate way to create a streamplot based on the data I have? I have tried using the griddata function in scipy to create grids out of the velocity data, but I'm not quite sure how to decide on appropriate xi values (or from doc: "Points at which to interpolate data") when using this function.
Please excuse the generality of this question, as it might be more about the theory behind a streamplot than python syntax itself.
Any help would be much appreciated!
I love Matplotlib but sometimes the lack of 'idiots guide' examples is infuriating.
Long story short, I have several large lists of XYZ positional data from simulated motion throw 3D space from multiple entities. I currently do this statically, i.e.
for entity in entities:
x=map(itemgetter(0),positionLog(entity))
y=map(itemgetter(1),positionLog(entity))
z=map(itemgetter(2),positionLog(entity))
ax.plot(x,y,z,label=nameLookup(entity))
plt.show()
What I'd like to do is to have these lists 'step' out, i.e where all the entities are at t(0), then add in the t(1) points and so on.
However, it's not clear in any of the examples I've found how to accomplish this. The examples that I see show how to do individual runs, i.e. for one entity, but I can't see how to do all (N) in lock-step.
Suggestions please? :D
So one way to do what I think you want is to make x, y, and z lists. add t(0) to the plot and show the plot. Next, append t(1) to you original x, y, z lists, update the plot with the new x, y, z coordinates, then refresh the plot (which is the old way of doing animations in matplotlib).
This example: http://matplotlib.sourceforge.net/examples/animation/basic_example.html
uses the built in animation function to generate an animation the new way, which is exactly what I think you want, just add your third coordinate.