Is there a function in Python that is analogous to Vq = interp2(X,Y,V,Xq,Yq) from Matlab? I trying to extract the values at Xq, Yq from V. I have tried to use Vq=interp2d(X0,Y0,V,kind='linear'), but it does not work as I wished.
Related
I came across a Rose plot obtained with Plots.jl package in Julia:
https://goropikari.github.io/PlotsGallery.jl/src/rose.html
Two things are not clear to me. The first one is what is Julia doing on the line:
θ = 0:2pi/n:2pi
It seems that the output is (lower limit):(bin size):(upper limit) but I haven't seen this type of arithmetics previously where two ranges are divided. The second thing is that I would like to obtain a histogram polar plot as it was done with R (Making a polar histogram in ggplot2), but I haven't found the documentation for line styles or how to do it in Plots.jl. Thanks.
Note that start:step:end is a common syntax in creating ranges. Let's dissect the line:
# `pi` is a reserved variable name in Julia
julia> pi
π = 3.1415926535897...
# A simple division
julia> 2pi/1
6.283185307179586
# Simple multiplication
julia> 2pi
6.283185307179586
So the 0:2pi/n:2pi creates an object of type StepRange that starts from 0 up to 2pi with steps of size 2pi/n.
In the case of desired plot, you can use the PlotlyJS.jl package. As they provided an example here. (Scroll down until you see "Polar Bar Chart")
I tested the code myself, and it's reproducible expectedly. Unfortunately, I don't know anything about the R language.
julia> using RDatasets, DataFrames, PlotlyJS
julia> df = RDatasets.dataset("datasets", "iris");
julia> sepal = df.SepalWidth;
julia> plot(
barpolar(
r=sepal
)
)
Results in:
I am using Plots for visualizing 3d-plots with Julia, and I am trying to change camera angle of my plot. In matplotlib in Python, I know that I can use ax.view_init(elev, azim) to change the camera angle, but on Plot.jl, I could not find solution to change the angle.
Is there any equivalent function with ax.view_init(elev, azim) in Python in Julia ?
Example of Plot
using Plots
plot()
for i in 1 : 5
a = rand(10); b= rand(10); c = rand(10);
plot!(a,b,c, seriestype=:scatter)
end
plot!()
As you can read in the manual you can use the camera keyword argument (aliases are: cam, cameras, view_angle, viewangle). This argument sets the view angle for 3D plots. Its value is required to be a tuple (azimuthal, elevation) and the default setting is (30, 30).
I have a data structure that stores 3D structures as a bounding volume hierarchy of spheres and outputs a file containing the 3D coordinates and the radii of the spheres. I'm trying to plot these spheres using Makie.jl, but I've so far been unsuccessful. After extracting the coordinates from the XSLX document I had them stored in and assigning each column to the appropriate variable, I attempted to write a for loop to successively plot each coordinate. But for some reason, the output is always a 2D plot, even though the argument I'm passing uses 3 coordinates. So far I've tried passing the coordinates in as a tuple, iterating through a list of tuples; the code below plots the closest to what I want to end up with (the Stanford Rabbit). What is it that I'm missing, or where am I going wrong? Thanks in advance! (Yes I am new to Julia)
using XLSX, GLMakie
xf = XLSX.readxlsx("BunnySphereTree.xlsx")
sh = xf["BunnySphereTree"]
x = sh["A"]
y = sh["B"]
z = sh["C"]
r = sh["D"]
leeroy = scatter((x[1],y[1],z[1]))
current_figure()
for i in 2:length(x)
jenkins = scatter!((x[i], y[i],z[i]))
end
current_figure()
I have also tried to modify the example presented here to fit what I want, but I've so far been unsuccessful. Once again, any help is appreciated and thank you in advance!
I'm having trouble converting an R function to a latex formula. I have a df (m) of x and y coordinates that I then calculate a centroid from using the following R function:
cnt = c(mean(m[,1]),mean(m[,2]))
I then take that same list and calculate the distance from each x,y pair to that centroid. Lastly, I then take the mean distance over all the records from the centroid using the following code:
mean_distance <- mean(apply(m,1,function(x,cnt) {(sqrt((x[1] - cnt[1])^2+(x[2]-cnt[2])^2))},cnt))
I think I got the first part figured out (finding the centroid coordinates)
cnt\left(x, y\right) = \frac{\sum x_{i}}{n}, \frac{\sum y_{i}}{n}
I'm having trouble with the second calculation. I'm new to latex and would like to create (an elegant) formula to include in a paper I am writing. Is there any easy way to convert this R code to latex?
You can try something like
$$
C(x,y) = (C_1, C_2) = \left( \frac1n\sum_{i=1}^n x_i,\frac1n\sum_{i=1}^n y_i\right)
$$
$$
d = \frac1n \sum_{i=1}^n \sqrt{\left( x_i-C_1\right)^2+\left( y_i-C_2\right)^2}
$$
if I understood what you want.
I'm porting some code from R to Julia, and struggling with translating R's spline function. I need a Julia function:
function spline_j(x,y,xout)
that yields the same return as calling the R function:
spline(x,y,,"fmm",,,xout)
i.e. using the method of Forsyth, Malcolm and Moler, which is the default method in R.
My x and y are always 1-dimensional, but the points of x are not regularly spaced. That non-regularity seems to rule out using the pure-Julia Interpolations package as the documentation states "presently only LinearInterpolation supports irregular grids".
The Dierckx package supports irregular x, so a candidate for spline_j is:
using Dierckx
function spline_j(x, y, xout)
spl = Dierckx.Spline1D(x, y)
spl(xout)
end
which matches R's spline function if method is "natural".
Is it possible to replicate R's "fmm" method in Julia?
Following this PR https://github.com/JuliaMath/Interpolations.jl/pull/238 (merged as #243), Interpolations.jl actually has a number of excellent monotonic spline interpolation algorithms that support irregular grids, including Fritsch-Carlson (1980), Fritsch-Butland (1984), and Steffen (1990).
It doesn't seem to be reflected in the docs yet, but the options are visible in the following git diff
For example:
using Interpolations, Plots
x = sort(2*rand(10))
y = x.^2 .+ rand.()
itp = interpolate(x,y,FritschCarlsonMonotonicInterpolation())
xq = minimum(x):0.01:maximum(x)
plot(x,y, seriestype=:scatter, label="Data", legend=:topleft, framestyle=:box)
plot!(xq, itp.(xq), label="Interpolation")
If you prefer different interpolation methods, you can also substitute
FiniteDifferenceMonotonicInterpolation,FritschButlandMonotonicInterpolation, or SteffenMonotonicInterpolation for FritschCarlsonMonotonicInterpolation.