I am using the contour function from Julia's Plots to plot level curves. I want to extract a list of x coordinates and a list of y coordinates corresponding to the level curves from the plot, e.g., something like this. Is there a way to do it in Julia?
Not for contour, unfortunately. For most plot types you can extract the input data of, e.g. the first series in the first subplot, with p[1][1][:x]. But for contour in particular Plots does not generate the level curves, it simply passes the matrix to the backend that then does the computation and display.
Related
I am using cpsd (https://cran.r-project.org/web/packages/gsignal/gsignal.pdf) to find the cross-spectral density between two signals. It seems that there is no way to define the frequencies I want to get the density for. E.g. in MATLAB I can do cpsd(x,y,window,noverlap,f,fs), where f=[2,10], so the output will be only two values. Is there an alternative for R?
I am trying to stack multiple 2d plots into a single 3d plot in R.
For example, I want to try and put these plots
into a single 3d image. The z axis would be the biomass density, y axis be the size and the x axis be the time step (and then hopefully I could use a surface plot to join up all the lines). My aim is to try and show the wave travelling through the size over a long period of time instead of showing lots of images.
Does anyone know how to do this?
I want to use the iterative plot function plot for in gnuplot for a parametric plot.
set parametric
f(x) = x
plot for [i=1:2] t,f(i*t)
However, as I learned in this Question, the for iteration ends after a comma. So the iteration only applies to t and not to f(i*t). But since a parametric plot needs a pair of functions separated by a comma, how can I tell gnuplot to iteratively plot my parametric plot?
Did you actually try it? gnuplot distinguishes a comma between parametric coordinates and the end of a plot-element as it is called (which can contain a for-loop): this is simply done by counting the number of coordinates given.
E.g.,
set parametric
set size ratio -1
plot for [i=1:3] cos(t),i*sin(t) title "Ellipse ".i, \
for [i=1:3] i*cos(t),i*sin(t) title "Circle ".i
If you do
plot for [i=1:3] cos(t),i*sin(t),i*cos(t),i*sin(t)
then you keep the 3 ellipses (well, including the circle when i=1), and have one circle plotted for i=3 (the value i kept after the for loop) from the last pair of coordinates.
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.
I am writing an regression algorithm which tries to "capture" points inside boxes. The algorithm tries to keep the boxes as small as possible, so usually the edges/corners of the boxes go through points, which determines the size of the box.
Problem: I need graphical output of the boxes in R. In 2D it is easy to draw boxes with segments(), which draws a line between two points. So, with 4 segments I can draw a box:
plot(x,y,type="p")
segments(x1,y1,x2,y2)
I then tried both the scatterplot3d and plot3d package for 3D plotting. In 3D the segments() command is not working, as there is no additional z-component. I was surprised that apparently (to me) there is no adequate replacement in 3D for segments()
Is there an easy way to draw boxes / lines between two points when plotting in three dimensions ?
The scatterplot3d function returns information that will allow you to project (x,y,z) points into the relevant plane, as follows:
library(scatterplot3d)
x <- c(1,4,3,6,2,5)
y <- c(2,2,4,3,5,9)
z <- c(1,3,5,9,2,2)
s <- scatterplot3d(x,y,z)
## now draw a line between points 2 and 3
p2 <- s$xyz.convert(x[2],y[2],z[2])
p3 <- s$xyz.convert(x[3],y[3],z[3])
segments(p2$x,p2$y,p3$x,p3$y,lwd=2,col=2)
The rgl package is another way to go, and perhaps even easier (note that segments3d takes points in pairs from a vector)
plot3d(x,y,z)
segments3d(x[2:3],y[2:3],z[2:3],col=2,lwd=2)