I have tho following issue: i have two Numpy arrays containing the x,y coordinates of many (potentiality, tens of thousand) of disks, whose (different) radii are contained in a third array r. Both the radii and the coordinates are measured with the same units. I would like to plot them with the exact radius given by r but in a fast way.
I have found some partial solutions (Matplotlib scatter can use the three arrays and it is reasonably fast, but the size is scale in points, the Circles instances are too slow and Mayavi is in my opinion an overkill since the problem is 2d).
The speed is important due to the large number of circles I want to plot. Is there a simple native solution that did not come to my mind?
Related
I have two arrays of n by n indicating U and V velocities. I wish to plot the streamlines.
I am aware this can be done for regularly spaced arrays using streamplot. I'm currently working on an array that is relatively close to regularly spaced so the issues are not that big. However, soon I will be working on arrays where the arrays are far from evenly spaced. With the coordinates following curves.
I've looked for a way to plot these but I cannot seem to find any modules. The only two ways I could think of doing it are:
approach the actual solution with a regularly spaced grid
use a vector field instead of a streamline field (similar to what was done here Streamlines for irregular spaced wind data in R?)
My question is if there is a module which I can use and if not, what would be the best approach to achieve a suitable result.
I am stuck with python and matplotlib imshow(). Aim is it to show a twodimensonal color map which represents three dimensions.
My x-axis is represented by an array'TG'(93 entries). My y-axis is a set of arrays dependend of my 'TG' To be precise we have 93 different arrays with the length of 340. My z-axis is also a set of arrays depended of my 'TG' equally sized then y (93x340).
Basically what I have is a set of two-dimensonal measurements which I want to plot in color dependend on a third array. Is there a clever way to do that. I was trying to find out on my own first, but all I found is that most common is the problem with just a z-plane(two-dimensonal plot). So I have two matrices of the order of (93x340) and one array(93). Do you know a helpful advise.
Without more detail on your specific problem, it's hard to guess what is the best way to represent your data. I am going to give an example, hopefully it is relevant.
Suppose we are collecting height and weight of a group of people. Maybe the index of the person is your first dimension, and the height and weight depends on who it is. Then one way to represent this data is use height and weight as the x and y axes, and plot each person as a dot in that two dimensional space.
In this example, the person index doesn't really have much meaning, thus no color is needed.
I am trying to work out an efficient way of drawing line patterns on a screen using python.
A while ago I cobbled together some code that could drive a LAser Spirograph. Which is basically 3 circles each rotating around a moving point of the circumference of each other. This produces a series of point that trace out various patterns depending on the relative speeds each of the circles are spinning.
So now i have a long list of x,y cord that I want to plot as a single line, is there a function in python (currently playing with Pygames) that will take a series of points and conect them with a smooth curved line.
for example say i have a few hundred point that describe the pattern in this link, is there a "simple" way in Python to render he full pattern to screen. I am assuming this would be faster than trying to plot each of several thousand points to get the appearance of a line.
EDIT
I have been assuming that there would be a faster way to draw say a semi circle to the screen by passing a function the start and end point plus the radius. rather than calculate 2,000 points on the curve and plotting them separately either as points or short straight lines. I also am assuming its quicker to plot a straight line 100 points long than outputting the same line as separate points?
Disclaimer This is not an answer
To expand on my comment above
You don't want the curve. You want to sample the curve with a frequency sufficient to fool perception
have a look at the effects of denser vs coarser sampling on the perception of what is drawn on a screen
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, np.pi*3, 301)
x = np.sin(t)
each of the points (t[i], x[i]) represent a point, here a pont in a sine curve, in your application a more complex curve, so let's plot these points using a different sampling step, to see if the sampling rate has an effect on your perception of what is drawn...
for step in (1, 25, 50):
plt.plot(t[::step], x[::step], label='step=%d'%step)
# ^^^^ ^^^^
plt.ylim((-1.05, 1.05))
plt.legend(loc='best')
that gives me
I dare say, with a sufficiently high sampling rate what is drawn looks like a curve, even if it is a sequence of straight segments (as it's apparent when you look at the other two istances of t vs x).
In other comments, you were told which pygames function you can use to do your deed.
I am currently working on a project where I have to bin up to 10-dimensional data. This works totally fine with numpy.histogramdd, however with one have a serious obstacle:
My parameter space is pretty large, but only a fraction is actually inhabited by data (say, maybe a few % or so...). In these regions, the data is quite rich, so I would like to use relatively small bin widths. The problem here, however, is that the RAM usage totally explodes. I see usage of 20GB+ for only 5 dimensions which is already absolutely not practical. I tried defining the grid myself, but the problem persists...
My idea would be to manually specify the bin edges, where I just use very large bin widths for empty regions in the data space. Only in regions where I actually have data, I would need to go to a finer scale.
I was wondering if anyone here knows of such an implementation already which works in arbitrary numbers of dimensions.
thanks 😊
I think you should first remap your data, then create the histogram, and then interpret the histogram knowing the values have been transformed. One possibility would be to tweak the histogram tick labels so that they display mapped values.
One possible way of doing it, for example, would be:
Sort one dimension of data as an unidimensional array;
Integrate this array, so you have a cumulative distribution;
Find the steepest part of this distribution, and choose a horizontal interval corresponding to a "good" bin size for the peak of your histogram - that is, a size that gives you good resolution;
Find the size of this same interval along the vertical axis. That will give you a bin size to apply along the vertical axis;
Create the bins using the vertical span of that bin - that is, "draw" horizontal, equidistant lines to create your bins, instead of the most common way of drawing vertical ones;
That way, you'll have lots of bins where data is more dense, and lesser bins where data is more sparse.
Two things to consider:
The mapping function is the cumulative distribution of the sorted values along that dimension. This can be quite arbitrary. If the distribution resembles some well known algebraic function, you could define it mathematically and use it to perform a two-way transform between actual value data and "adaptive" histogram data;
This applies to only one dimension. Care must be taken as how this would work if the histograms from multiple dimensions are to be combined.
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.