flutter/dart: draw 2d graph with gradient interpolation between data points - python

I'd like to draw a 2D time series in color with flutter.
Goal
Obviously, it's different from 1D data in that along the y-axis I have a vector of discrete data points at each x, but the color graph must be continuous. So I'd love to use color gradients between these data points to present a continuous heat map.
The end result would look like a spectrogram
With Python's matplotlib, this would be a simple imshow() call.
Reference
From this question: How to do a Gradient effect from topLeft to botttomRgiht in Flutter Shader?
I learned that I could use flutter's shader to create color gradients. That's fine.
Problem
But it seems to me that I would need hundreds of shaders between the data points in order to draw dynamic gradients I want. The y-vector could be as big as 1000 to 2000 data points at each moment.
Is there a simpler way to achieve what I want, such as using as few shaders as possible?

Related

How do you find the coordinates of a plane with a minimized distance strictly above a 3D dataset (python)?

As the title states, I need to make a plane above a 3D dataset in Python. There should be no data points above such plane, and the distances between the plane and the dataset should be optimized such that the plane somehow generalizes the whole data.
this is the 3d surface plot
(this is another example) the plane should look like this
I've been stuck for months on how to start/approach this problem. Should I start looking for the maximums in the data? Should I start on finding the peak in the middle and tamper around the possible slopes of the plane? Or are there other appropriate mathematical methods for this?
Thanks ahead.

Plotting a coastline on cartesian grid in matplotlib

I am making maps of meteorological data (x,y-coordinates in m) using matplotlib.pyplot.contourf(). I want to plot a coastline, but all the examples I find on internet use lat-lon data (with cartopy or basemap).
Is there a way (without transforming the data to a lat-lon grid) to plot a coastline on my cartesian grid? I know size of the grid, and its center's lat-lon coordinates.
I haven't tried anything but look for similar examples, which I could not find.
The solution is to use cartopy's gnomonic projection: https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html#gnomonic , e.g.
proj =ccrs.Gnomonic(central_latitude=0, central_longitude= 0)
The origin of the data need to be specified (in lat-lon), and it expects the data coordinates to be distance in meters from that origin. Then, the normal cartopy features (like coastlines) work as usual.

Plot a Colored Contour Map on a 3D surface in Matplotlib

I am currently working on a 3D simulation data. I have a 3D surface, for simplicity, lets say, I have a hemispherical surface. So naturally, I have all the (x,y,z) coordinates that make up the surface. Now I also have a fourth array having the values of some variable (say Pressure for example) at all the (x,y,z) locations that make up the hemispherical surface. My aim is to plot the hemispherical surface and the surface should be coloured according to the fourth array (i.e according to the value of Pressure at that surface).
I have tried pyplot.scatter function from matplotlib, where i use pyplot.scatter(x,y,z, c= Pressure_array) but it leaves me with an artefact like the one shown below (image shows a zoomed in portion of the entire plot)
Notice the fringe like circular pattern. This arises because a Cartesian grid is sampled by a spherical surface and the same is plotted by the scatter points. This pattern remains even upon interpolation of the color values
I am looking for an alternative to the scatter plot method where the surface will be smoother and the circular fringes will be absent. I am aware that matplotlib has surface plots, but i am unable to use it because there, the 'z' coordinate sets both, the height of the plot in 3D and essentially the Color of the surface as well.
Any alternative to scatter plot or surface plot, or a way to get the same domne with the surface plot function in matplotlib will be much appreciated.

"continuous" plotting in Pygame

I do I plot a "continuous", moving plot in Pygame, like the plot in this "NetLogo" simulation? My main difficulty is not the plotting itself (lines between points) but the process of moving the framework of the plot when the curve getting close to the edge of the box.
Thank you.
Ok, so you can make a plot similar to the one in the application in the following way:
create a surface of the size of the graph. Then create a pixel array, so you will be able to modify the graph.
pxarray = pygame.PixelArray (surface)
you can then manipulate the array like any other array:
pxarray[x][y] = 0xFF00FF # this will set pixel at x,y to purple
you can normally then normally blit the surface to the screen.
more on pixel arrays : http://www.pygame.org/docs/ref/pixelarray.html
EDIT: Using pxarray, and transform you will have a shrinking graph if your numbers go out of range. Simply when the point is too big for the plot, you add enough rows, and use transform.scale to scale back to the original resolution.

How interpolate 3D coordinates

I have data points in x,y,z format. They form a point cloud of a closed manifold. How can I interpolate them using R-Project or Python? (Like polynomial splines)
It depends on what the points originally represented. Just having an array of points is generally not enough to derive the original manifold from. You need to know which points go together.
The most common low-level boundary representation ("brep") is a bunch of triangles. This is e.g. what OpenGL and Directx get as input. I've written a Python software that can convert triangular meshes in STL format to e.g. a PDF image. Maybe you can adapt that to for your purpose. Interpolating a triangle is usually not necessary, but rather trivail to do. Create three new points each halfway between two original point. These three points form an inner triangle, and the rest of the surface forms three triangles. So with this you have transformed one triangle into four triangles.
If the points are control points for spline surface patches (like NURBS, or Bézier surfaces), you have to know which points together form a patch. Since these are parametric surfaces, once you know the control points, all the points on the surface can be determined. Below is the function for a Bézier surface. The parameters u and v are the the parametric coordinates of the surface. They run from 0 to 1 along two adjecent edges of the patch. The control points are k_ij.
The B functions are weight functions for each control point;
Suppose you want to approximate a Bézier surface by a grid of 10x10 points. To do that you have to evaluate the function p for u and v running from 0 to 1 in 10 steps (generating the steps is easily done with numpy.linspace).
For each (u,v) pair, p returns a 3D point.
If you want to visualise these points, you could use mplot3d from matplotlib.
By "compact manifold" do you mean a lower dimensional function like a trajectory or a surface that is embedded in 3d? You have several alternatives for the surface-problem in R depending on how "parametric" or "non-parametric" you want to be. Regression splines of various sorts could be applied within the framework of estimating mean f(x,y) and if these values were "tightly" spaced you may get a relatively accurate and simple summary estimate. There are several non-parametric methods such as found in packages 'locfit', 'akima' and 'mgcv'. (I'm not really sure how I would go about statistically estimating a 1-d manifold in 3-space.)
Edit: But if I did want to see a 3D distribution and get an idea of whether is was a parametric curve or trajectory, I would reach for package:rgl and just plot it in a rotatable 3D frame.
If you are instead trying to form the convex hull (for which the word interpolate is probably the wrong choice), then I know there are 2-d solutions and suspect that searching would find 3-d solutions as well. Constructing the right search strategy will depend on specifics whose absence the 2 comments so far reflects. I'm speculating that attempting to model lower and higher order statistics like the 1st and 99th percentile as a function of (x,y) could be attempted if you wanted to use a regression effort to create boundaries. There is a quantile regression package, 'rq' by Roger Koenker that is well supported.

Categories