4D (3D and color) level sets - r

How can I create 4D (3D plus color) plot that will have multiple 3D surfaces with different colors?
I have only 3 vectors of integers (x, y, z) and a function with 3 arguments (x, y, z) that returns integer = color. Function accepts integers, not whole vectors and returns single integer.
I'm OK with either R or python 3 solution.
Surfaces would be my level sets.
In every solution in Internet I have found, colors are bound by one of the dimensions (usually z) and I do not want this. I want my color to be separate information.
Is it possible if vectors have different lengths?

Related

Colorplot in Julia with awkward data format

I have data in the form of a list of tuples (x,y,z) with no particular ordering on the (x,y) values. I want to make a color plot in the x-y plane where z is represented by a color, using the PyPlot function
pcolor
The issue is this function accepts data in the format arr_x,arr_y,image where arr_x and arr_y are 1D arrays and image is a 2d Array such that image[i,j] corresponds here to the z value for x=arr_x[i],y=arr_y[j].
Is there a simple way to do this (without constructing the 2D array image, which would be annoying).
Are you looking for scatter?
using Plots, Unzip # Unzip to go from list of tuples to tuple of lists
data = [(randn(), randn(), randn()) for _ in 1:200] # list of (x,y,z) tuples
x, y, z = unzip(data) # get vectors out of the tuple
scatter(x, y, zcolor=z)
will output

Sets of arrays of different variable length (Julia)

E.g., when processing the set of plane contours:
each one consists of N nodes and may be described by the matrix N*2
(x, y coordinates of every node).
The number of nodes in the contour is changed during processing.
What is the simplest recommended object (data type) in Julia for such set of contours?
Simplest possible in what way? See GeometryTypes.jl. The "simplest" object, by some definitions of simple, is a vector of 3D points, with (x, y) the node coordinates and z the contour height value. You could use Point3f0 with Float32 or Point3d{T} for Int or Float64. Here you could index with ranges, as Matt suggested above.
If there is a desire for "simple" here to mean keep the contour value in a different category altogether than the (x, y) points, perhaps to save memory, then a Dict{Float32, Vector{Point2f0}}() would do that. The Dict keys would represent the contour numbers. This allows quick indexing by contour but terrible indexing by X and Y ranges as a price for the better memory usage.
If the contour indexes are so regular and predefined that storing them with the points does not matter, you could use Vector{Vector{Point2f0}}, a vector of vectors of Point2f0, with one vector of Point2f0 per contour in your vector of vectors.

How to find whole distance between two points in a curved line in R?

I have a similar line graph plotted using R plot function (plot(df))
I want to get distance of the whole line between two points in the graph (e.g., between x(1) and x(3)). How can I do this?
If your function is defined over a fine grid of points, you can compute the length of the line segment between each pair of points and add them. Pythagoras is your friend here:
To the extent that the points are not close enough together that the function is essentially linear between the points, it will tend to (generally only slightly) underestimate the arc length.
Note that if your x-values are stored in increasing order, these ẟx and ẟy values can be obtained directly by differencing (in R that's diff)
If you have a functional form for y as a function of x you can apply the integral for the arc length -- i.e. integrate
∫ √[1+(dy/dx)²] dx
between a and b. This is essentially just the calculation in 1 taken to the limit.
If both x and y are parametric functions of another variable (t, say) you can simplify the parametric form of the above integral (if we don't forget the Jacobian) to integrating
∫ √[(dx/dt)²+(dy/dt)²] dt
between a and b
(Note the direct parallel to 1.)
if you don't have a convenient-to-integrate functional form in 2. or 3. you can use numerical quadrature; this can be quite efficient (which can be handy when the derivative function is expensive to evaluate).

Why is my plot3d white in SciLab?

t = 0:%pi/50:10*%pi;
plot3d(sin(t),cos(t),t)
When I execute this code the plot is done but the line is not visible, only the box. Any ideas which property I have to change?
Thanks
The third argument should, in this case, be a matrix of the size (length arg1) x (length arg2).
You'd expect plot3d to behave like an extension of plot and plot2d but it isn't quite the case.
The 2d plot takes a vector of x and a vector of y and plots points at (x1,y1), (x2,y2) etc., joined with lines or not as per style settings. That fits the conceptual model we usually use for 2d plots - charting the relationship of one thing as a function of another, in most cases (y = f(x)). THere are other ways to use a 2d plot: scatter graphs are common but it's easy enough to produce one using the two-rows-of-data concept.
This doesn't extend smoothly to 3d though as there are many other ways you could use a 3d plot to represent data. If you gave it three vectors of coordinates and asked it to draw a line between them all what might we want to use that for? Is that the most useful way of using a 3d plot?
Most packages give you different visualisation types for the different kinds of data. Mathematica has a lot of 3d visualisation types and Python/Scipy/Mayavi2 has even more. Matlab has a number too but Scilab, while normally mirroring Matlab, in this case prefers to handle it all with the plot3d function.
I think of it like a contour plot: you give it a vector of x and a vector of y and it uses those to create a grid of (x,y) points. The third argument is then a matrix whose dimensions match those of the (x,y) grid holding the z-coordinates of each point. The first example in the docs does what I think you're after:
t=[0:0.3:2*%pi]';
z=sin(t)*cos(t');
plot3d(t,t,z);
The first line creates a column vector of length 21
-->size(t)
ans =
21. 1.
The second line computes a 21 x 21 matrix of products of the permutations of sin(t) with cos(t) - note the transpose in the cos(t') element.
-->size(z)
ans =
21. 21.
Then when it plots them it draws (x1,y1,z11), (x1,y2,x12), (x2,y2,z22) and so on. It draws lines between adjacent points in a mesh, or no lines, or just the surface.

vectors vs. vector graphics

What (if any) is the relationship between vectors used in programming languages (e.g. arrays) and vector graphics?
Why do they share the term vector? Does it represent some analogous aspect of their nature or is it coincidence?
When thinking about it, a bitmap image would fit the term vector graphic better since it's represented by an array of pixels..
a vector is a set of values, which "normally" (mathematicians would kill me) represent the coefficients of a linear combination of things (functions, or other vectors).
For example, when you say
[4, 3, 7]
and your basis is the set of power exponents of x (i.e. 1, x, x^2, x^3 etc...), this vector expresses the polynom
4 + 3x + 7 x^2
if you use a different basis, for example arbitrary directions in 3d space, that same vector expresses a direction in 3d space.
4i + 3j + 7k
(lateral consideration: please note that 3d space is a finite vectorial space of dimension 3, while the polynomial space is an infinite vectorial space, or a Hilbert space as it is better defined)
This is a vector (think an arrow) pointing in a specific direction in space, from an origin to an end. The convention is that i,j, and k are the so called basis set vectors of the 3d vectorial space, where the coordinates of each point are expressed as x,y and z. In other words, every point in space, and every direction in space, can be expressed with a triple of numbers (a vector) x, y, z which represents the spatial vector x * i + y * j + z * k.
In vector graphics, you express graphical entities not as a grid of pixel (raster graphics) but as mathematical formulas. A curve is described as a parametrized mathematical expression. This opens up a lot of nice properties for displaying, because a mathematical description has basically infinite resolution. You can also apply mathematical transformation on these entities, like rotation, without ruining its description, and these transformations are deeply rooted in linear algebra, the discipline governing transformation of vectorial spaces, matrices and so on...
They share a root meaning in mathematics.
The graphics meaning (a continuously valued offset from on arbitrary position in space), derives from the fact that you use mathematical vectors to represent it (e.g. one to represent the starting point and to represent the offset).
The programming language meaning (an ordered set of numbers) is one way of writing down the mathematical version.
A vector is an ordered group of values, such as <1, 2, 3>. It is different to an array because it is a fixed size and represents a number of values and their position in the vector is significant. An array is just an ordered collection of things. The order of elements matters but not their position. The things in it are generally all of the same type.
If the vector represented <# apples, # oranges, # pears> then it could be interpreted as <1 apple, 2 oranges, 3 pears>. If it represented <X position, Y position, Z position> then the above might mean <1 in the X axis, 2 in the Y axiz, 3 in the Z axis> (a Euclidean vector). Thus vectors can represent co-ordinates in arbitrary dimensions and are used to store information in vector graphics.
I guess it comes from the mathematical term 'vector', which is a geometrical concept. When you operate on mathematical vectors, which (in theory) have their values in continuous domains, instead of on discrete pixels, you can compute with arbitrary precision. In a graphics application, it means that you can retain precise point positions regardless of the zoom factor you are displaying your picture at.
Vector graphic is different that 'normal' graphic because it can be zoomed without aliasing. It is called vector graphic because each line or other object are represented by a vector instead of the "by pixel" normal grahic.

Resources