How to plot 3D direction and speed using R or MATLAB? - r

I am looking for a way to plot a wind 3D direction in R or MATLAB.
There are 3 given vector components:
u : x-axis (horizontal)
v : y-axis (horizontal)
w : z-axis (vertical)
For plotting wind directions in 2D, there is the traditional way of using a rose plot like this: https://commons.wikimedia.org/wiki/File:Wind_rose_plot.jpg
Do you have any idea, how I can plot this in 3D using the R statistic engine or MATLAB, by using the additional w vector?
Thanks a lot!

In MATLAB quiver3 will be the most relevant to your case. More information and examples here.

Related

newbie: holoviews Curves from pandas dataset columns

I have a pandas dataframe with columns labeled...
x
y
true_x
true_y
I would like to plot a curve of true_x vs true_y overlaid with
points y vs x.
The tutorials leave me baffled since they only describe simple 2D and 3D examples.
We're about to start working extensively on additional documentation so that's good feedback. To create a simple plot like that simply declare a Curve and a Scatter object each with the appropriate kdims and vdims and overlay them using the mul operator:
curve = hv.Curve(df, kdims=['true_x'], vdims=['true_y'])
scatter = hv.Scatter(df, kdims=['x'], vdims=['y'])
curve * scatter

Smooth polygon in polar plot- R package

In R package,
is there any way to smoothen the polygon in a polar.plot?
I tried to use the splines, but could not find a way to insert the curved line in the polar.plot..
(I am a begginer in R programming)
I know that mathematically with polar plotting you can get smoothed polygons. An example here is for the square if you plot: 1 + Sin[4*x]/20 from 0 to 2 $\pi$ you will get a smoothed square. Change 4 to 5 and adjust the other constants by interpolation and you may find yourself happy.

Contour plot with 90 degree angles

I have a matrix, say cmat <- matrix(c(0,0,1,0,1,1,0,1,1),3,3) and I would like to plot the exact contours of the "region" with containing ones.
When using a contourplot(cmat) what I get is lines that define a sort of "smoothed" contour rather than following exactly the tiles. What I would like is a graph made only out of vertical and horizontal lines.
Does anyone know a function performing that?
Thanks in advance,
Renzu

polar image plot, how to do it with R?

I cannot find a straightforward way to make a nice image plot in R, but in polar coordinates. I'm basically attempting to find a R equivalent for the 'polarplot3d' function in MATLAB. I've been playing around with ggplot2 package but without much luck. Am I missing a package that contains functionality for what I'm attempting? thanks in advance for any pointers.
Ok, I'm trying to be more clear about what I'm trying to do. Lets say I want to define a polar coordinate grid, increments in the radial direction are 50m and 2.5 degrees in theta. This should look like a dartboard.
My data (r and angle in below code) are correspond to a radial distance measure and an angle. My desired z-value is the counts of a bivariate histogram between r and angle within the increments described above defining the grid.
My data is like the following:
# synthetic data for angle and distance #
angle <- rnorm(500,mean=90,sd=15)
r <- rnorm(500,mean=700,sd=200)
# bivariate histogram #
observations <- table(cut(angle,breaks=c(seq(0,360,by=2.5))),cut(r,breaks=c(seq(0,1400,by=50))))
# the 'z' data are in observations for each bin of bivariate histogram #
# hot to plot a polar coord image? #
It's very slow to render on my system, but
library(reshape2)
library(ggplot2)
mm <- melt(counts)
ggplot(mm,aes(Var1,Var2,fill=value))+geom_tile()+coord_polar()
ggsave("polar1.png")
appears to work.
I think the following could work. Use mapproject() from the maproj library to transform my xy coordinates acording to a polar projection (or another), Then use as.image() (from fields package) function to build a image object from my new coordiantes and my Z values. Eventually use image.plot().
library("mapproj")
xyProj <- mapproject(x, y, projection="conic", parameters=-90)
library("fields")
im <- as.image(z, x=xyProj)
image.plot(im)

How do I plot a 3D graph in 2D with color in octave?

I have a function z=f(x,y) and want to plot it using octave, but don't want the plot to be in 3d, as in
octave:1> x=(1:300);
octave:2> y=(1:300);
octave:3> [xx,yy]=meshgrid(x,y);
octave:4> A=sin(xx/100).*yy;
octave:5> mesh(x,y,A)
but rather in 2d using colors for the values of z, like what you get using the gnuplot instruction
gnuplot> plot 'a.txt' matrix w image
if I save the matrix A in the file a.txt. The closest I have found is the command contourf, but the as you can see if you try it,
octave:7> contourf(xx,yy,A)
the result is far from optimal... Any suggestion?
Thanks
imagesc will plot a matrix of your "z" values using colors:
> imagesc(x, y, A)
This will be inverted vertically compared to contourf, but that's easily fixed:
> imagesc(x, flipud(y), flipud(A))
And in your example you don't even need to provide the variables x and y:
> imagesc(A)
> imagesc(flipud(A))

Resources