Making binned polar plots - plot

Python newbie here
I have 3 sets of 1x130677 data, theta (0 to 360), R (0 to 30) and C. I want to create a polar plot that is binned in 5 degrees of theta increments and and 1 unit length of R. The C values are C(theta,R) [-not a function], first data in theta and R correspond to the first data in C. Each bin should contain multiple C values and average them and then the whole plot will be color coded. This is a close example:Polar histogram in Python for given r, theta and z values
Any help making this plot is greatly appreciated!
thank you

Related

Create circular bins using x and y- coordinates

I am trying to split my data frame into circular bins from a specific point (center of the plot) using 2 variables (x and y coordinates). The aim is to bin the data into 5 different circles starting from a point (2255, 2008) where the total matrix is (5599X4000). Can someone help me do that using R?

Return the frequency in a bin of a 2D histogram in Julia

Suppose I have some 2D data points, and using the Plots package in Julia, a 2D histogram can be easily plotted. My task is to define a function that maps between a data point to the frequency of data points of the bin to which that point belongs to. Are there any functions that serve well for this task?
For example, as in the following 2D histogram:
And I would like to define a function, such that when I input an arbitrary data points that is within the domain of this histogram, the function will output the frequency of the corresponding bin. In the image above, when I input (0.1, 0.1), the function should output, say, 375 (I suppose the brightest grid there represents the frequency of 375). Are there any convenient functions in Julia to achieve the aforementioned task?
Edit:
using Plots
gr()
histogram2d(randn(10000), randn(10000), nbins=20)
A histogram is created from 10000 2D data points generated from standard normal distribution. Is there any function in Julia to input a 2D point and output the frequency of the bin to which the point belongs to? It is possible to write one myself by creating arrays and bins and counting the number of elements in the bin of an inputted data point but this will be the tedious way.
I'm not 100% sure whether this is what StatsPlots is doing, but one approach could be to use StatsBase's histogram which works for N dimensions:
using StatsBase, StatsPlots, Distributions
# Example data
data = (randn(10_000), randn(10_000))
# Plot StatsPlots 2D histogram
histogram2d(data)
# Fit a histogram with StatsBase
h = fit(Histogram, data)
x = searchsortedfirst(h.edges[1], 0.1) # returns 10
y = searchsortedfirst(h.edges[2], 0.1) # returns 11
h.weights[x, y] # returns 243
# Or as a function
function get_freq(h, xval, yval)
x = searchsortedfirst(h.edges[1], xval)
y = searchsortedfirst(h.edges[2], yval)
h.weights[x, y]
end
get_freq(h, 1.4, 0.6) # returns 32

How do I select data inside a density curve in R?

I have a 2 varaible data set that I have to plot (na and ob). I applied the kde2d kernel and plotted 1 to 4 sigma density curves (confidencebound). I need to select those points that are inside 2 sigma curves (letting out all those between 1 and 2 sigmas), but not just in the plot, I neet select them from the data set, put them in a new list. Could you please help me with this?
kde_BPT <- kde2d(na,ob, n=1000, lims=c(-2,2,-1.5,1.5))
confidencebound <- quantile(kde_BPT$z, probs=c(0.685,0.955,0.9975,0.99995), na.rm = TRUE)
The data are to large to paste here. I put here the plot if that helps, I need to know which data points (any colour) are in the area between the contour curves of 1 and 2 (sigmas).
The plot
Thanks for your help.

Plotting vectors with different spacing

Have a list of vectors with different length (of which first value represents the start and last value represents the end).
A 1.1005 1.1084 1.177 1.2024 1.2085 1.1588 1.0868 1.1584 1.0892
B 1.079 1.1086 1.1741 1.184 1.118 1.1068 1.1655
C 1.1684 1.1693 1.2885 1.326 1.3069 1.2584 1.1163 1.1841
D 1.2462 1.1749 1.2304 1.2039 1.2162 1.2933 1.1998 1.1422
Tried to manually space them in excel to produce this plot in the picture.
http://imgur.com/8Qyen76
Is there a way to plot the aggregate of n (beyond only 4 sets) number of theses values (with std dev) of these values on a graph (with y axis being values in the vectors, x axis being from start to end) using R?
Sets up plot area tehn draws splines with the values at equally spaced intervals on a line by line basis:
plot(NA, xlim=c(0,12), ylim=range(dat[-1],na.rm=TRUE) )
apply( dat[-1],1,function(x) lines(spline( x=seq(0,10,length=length(x[!is.na(x)])+1)[-1],
y=x[!is.na(x)])))
If you need the colors you can just save the values from the spline calls and plot with a for loop.

How to control Y-axis units using sm.density.compare()

I have used sm.density.compare to plot 3 density functions for data with values between -90 and +10. The Y axis is labeled "density" and has the range 0 - 1.0 as for proportions or probability.
I then plot 4 density functions for data with values between 0 and 1.0. I get a useful plot and the Y axis still reads "density" but the values are apparently counts and range between 0 and 12 or so.
The function sm.options does not seem to offer control of which you get. I'd like both to be probability or proportions.
I'm new to R but have a substantial history with other software.

Resources