Plotting 4 & 3 dimensional data - matlab - math

I have data set to plot with the following dimensions.
Density
Accessibility
Land use mix
Vibrancy
Help me with the steps of the task.
Expected output will be

It looks like somebody implemented a QUATPLOT(A,B,C,D,marker,string) function in Matlab:
Percentage values (A,B,C,D) are transformed into xyz coordinates, allowing plotting % of data in the tetrahedron.
Source code and documentation can be found at https://de.mathworks.com/matlabcentral/fileexchange/68595-3d-plotting-in-a-four-variable-system-quatplot

Related

julia vector differential equation: plot only the first n components of the vector

I am integrating a vector differential equation in Julia (the number of components is of the order of magnitude of 50). When I plot this solution, obviously this plot will be very crowded if I plot all the components, so I want to plot only let's say the first 10 components. I can't find how to do this. Also, instead of plotting the output for each component, I would like to plot not the output of the integration at each time step, but the hyperbolic tangent of this. I also don't find how to do this manipulation. I think the key problem is that I don't understand/find what kind of object the solution of a differential equation is in julia.
Here is a minimal working example that integrates the differential equation and plots the whole solution.
using DifferentialEquations
using Plots
using LinearAlgebra
N=50
J=0.18*randn(Float64,N,N)
g=1
function hDerivative(timederiv,h,p,t)
for i=1:length(h)
timederiv[i] = -h[i]
for j=1:length(h)
timederiv[i]=+timederiv[i]+J[i,j]*tanh(g*h[j])
end
end
end
function pltTimeVolution()
hinit=rand(Float64,N)
tspan=(0.0,50)
prob = ODEProblem(hDerivative,hinit,tspan)
sol=solve(prob)
plot(sol)
print(sol)
end
pltTimeVolution()
For help, take a look at the solution handling page: http://diffeq.sciml.ai/latest/basics/solution.html . The solution is both an abstract array and a continuous function. So you can for example get a continuous solution at 10000 evenly spaced time points like t=range(tspan[1],stop=tspan[2],length=10000), do A = sol(t) and that will give a 50x10000 timeseries of each solution at evenly spaced time points, and then sol[i,:] would be the timeseries of the ith variable at the time points t. You can use that to build the arrays you want an plot them. Full code like this:
t=range(tspan[1],stop=tspan[2],length=10000)
A = sol(t)
ts10 = sol[10,:]
Another way to do this is to solve with something like saveat=t, in which case the solution is an array which saves at those time points. This looks like:
t=range(tspan[1],stop=tspan[2],length=10000)
sol=solve(prob,saveat=t)
ts10 = sol[10,:]
Or you can make use of the plot recipe which does this kind of handling internally. Take a look at http://diffeq.sciml.ai/latest/basics/plot.html#Choosing-Variables-1 . You can do things like plot the first variable and then lay over the plot of the 10th variable like:
plot(sol,vars=(0,1))
plot!(sol,vars=(0,10))
The ! means its the mutating plot function, i.e. modify the previous plot by adding a new series. Then as noted in the documentation there are shortcuts, like
plot(sol,vars = [1, 3, 4])
will plot the 1st, 3rd, and 4th variables as functions of time. In this form, you can also specify what kind of transformation you want as a function. That's mentioned in the same place in the documentation. For example, the two-dimensional plot of time vs tanh would be the transformation function f=(t,y)->(t,tanh(y)), i.e. how you take in the 2D variable and spit out the 2D variable to plot is just pass through the first and tanh the second. Then using this, you'd use the plot command:
f=(t,y)->(t,tanh(y))
plot(sol,vars = (f,0,5))
to plot the tanh of the 5th variable against time.
These are a few different ways to manipulate the solution argument and generate the plots you need. Pick the one that works best for you.

Overlapping data contour on a map

I have gone through few tutorials and answers here in stackoverflow such as:
Overlap image plot on a Google Map background in R or
Plotting contours on an irregular grid or Geographical heat map of a custom property in R with ggmap or How to overlay global map on filled contour in R language or https://blog.dominodatalab.com/geographic-visualization-with-rs-ggmaps/
They either don't serve my purpose or consider the density of the data to create the image.
I am looking for a way to plot contour on a map of a certain data, and would expect the image to look something like this:
or something like this taken from https://dsparks.wordpress.com/2012/07/18/mapping-public-opinion-a-tutorial/:
I have a data here that gives a contour plot like this in plot_ly but i want this over the map given by latitudes and longitudes.
Please guide me on how this can be done. Any links to potential answers or codes would be helpful.
Ok I did some digging and figured that to plot the data -which in this case are point values randomly distributed across the Latitude and Longitude, one has to make it continuous instead of the discreetly distributed one. To do this I interpolated the data to fill in the gaps, this method is given in Plotting contours on an irregular grid and then take it from there. Now the interpolation here is done using a linear regression, one can use other methods such as IDW, Kriging, Nearest Neighbourhood etc for which R-packages are easily available. These methods are widely used in climatology and topographic analysis. To read more about interpolation methods see this paper.

Cross-Recurrence plots in R (with or without ggplot)

I have different time-series corresponding to different individuals and their location within a building (a categorical variable -- more like a room name).
I would like to study the similarity in movement of different individuals by something like cross-recurrence plots, where the two time-series correspond to the two axes and the actual points correspond to the presence/absence of individuals in the same room.
Has anyone tried doing such plots in R or while using ggplot? Any help would be great!
I haven't used this routine. I used only d2 dimension and Lyapunov exponent for EEG but this package Tisean (RTisean for your case) has a routine ['recurr'] that returns the specific plot.
This link has a nice wrap up of tutorials and links
Edited:
In this link you can find a nice example of application of recurrence plot.
The return variables of function recur(and similar functions of other packages) you can access after putting $ after the dataset (like database)
and you can access them inside in ggplot function and applying the appropriate aes.

R: getting data (instead of plot) back from sm.density.compare

I'm doing a density compare in R using the sm package (sm.density.compare). Is there anyway I can get a mathematical description of the graph or at least a table with number of points rather than a plot back? I would like to plot the resulting graphs in a different application, but need the data to do so.
Thanks a lot for the help,
culicidae

Make density cloud from point cloud

My question consists of two sub questions.
I have a graphical illustration presenting (some virtual) worst case scenarios sampled from history organized based on two parameters.
Image:
At this moment I have a point cloud. I would like to create nicely splined density cloud of my results. I would like the 3d spline to consider density of points when aproximating (so aproximate further around when there are less samples availabe and more exactly in more dense region of space)
Because then, having that density cloud, I would be able scale the density in each vertical line specified by the two input parameters, and that would make it a likehood function of each outcome - [the worst case scenario])
Second part is, I would like to plot it, at best as semi-transparent 3d-regions that would be forming sometihng like a fog around the most dense region.
Uh,wow.. that wasn't easy to explain. Sigh. :)
Thanks for reading that far.
So here is a way to generate 3D density plots using the ks package. Since you provided no data this example is taken directly from the documentation to plot(...) in the ks package
library(MASS)
library(ks)
x <- iris[,1:3]
H.pi <- Hpi(x, pilot="samse")
fhat <- kde(x, H=H.pi, compute.cont=TRUE)
plot(fhat, drawpoints=TRUE)

Resources