kernel-density

How to plot a 3D density map in python with matplotlib

▼魔方 西西 提交于 2019-11-28 15:36:03
I have a large dataset of (x,y,z) protein positions and would like to plot areas of high occupancy as a heatmap. Ideally the output should look similiar to the volumetric visualisation below, but I'm not sure how to achieve this with matplotlib. My initial idea was to display my positions as a 3D scatter plot and color their density via a KDE. I coded this up as follows with test data: import numpy as np from scipy import stats import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D mu, sigma = 0, 0.1 x = np.random.normal(mu, sigma, 1000) y = np.random.normal(mu, sigma, 1000) z

Integrate 2D kernel density estimate

北慕城南 提交于 2019-11-28 09:29:35
I have a x,y distribution of points for which I obtain the KDE through scipy.stats.gaussian_kde . This is my code and how the output looks (the x,y data can be obtained from here ): import numpy as np from scipy import stats # Obtain data from file. data = np.loadtxt('data.dat', unpack=True) m1, m2 = data[0], data[1] xmin, xmax = min(m1), max(m1) ymin, ymax = min(m2), max(m2) # Perform a kernel density estimate (KDE) on the data x, y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j] positions = np.vstack([x.ravel(), y.ravel()]) values = np.vstack([m1, m2]) kernel = stats.gaussian_kde(values) f = np

How to plot a 3D density map in python with matplotlib

余生长醉 提交于 2019-11-27 19:48:57
问题 I have a large dataset of (x,y,z) protein positions and would like to plot areas of high occupancy as a heatmap. Ideally the output should look similiar to the volumetric visualisation below, but I'm not sure how to achieve this with matplotlib. My initial idea was to display my positions as a 3D scatter plot and color their density via a KDE. I coded this up as follows with test data: import numpy as np from scipy import stats import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import

Specifying the scale for the density in ggplot2's stat_density2d

别说谁变了你拦得住时间么 提交于 2019-11-27 16:47:48
问题 I'm looking to create multiple density graphs, to make an "animated heat map." Since each frame of the animation should be comparable, I'd like the density -> color mapping on each graph to be the same for all of them, even if the range of the data changes for each one. Here's the code I'd use for each individual graph: ggplot(data= this_df, aes(x=X, y=Y) ) + geom_point(aes(color= as.factor(condition)), alpha= .25) + coord_cartesian(ylim= c(0, 768), xlim= c(0,1024)) + scale_y_reverse() + stat

Multivariate kernel density estimation in Python

北慕城南 提交于 2019-11-27 14:57:22
问题 I am trying to use SciPy's gaussian_kde function to estimate the density of multivariate data. In my code below I sample a 3D multivariate normal and fit the kernel density but I'm not sure how to evaluate my fit. import numpy as np from scipy import stats mu = np.array([1, 10, 20]) sigma = np.matrix([[4, 10, 0], [10, 25, 0], [0, 0, 100]]) data = np.random.multivariate_normal(mu, sigma, 1000) values = data.T kernel = stats.gaussian_kde(values) I saw this but not sure how to extend it to 3D.

Add density lines to histogram and cumulative histogram

倖福魔咒の 提交于 2019-11-27 10:37:03
问题 I want to add density curve to histogram and cumulative histogram, like this: Here is as far I can go: hist.cum <- function(x, plot=TRUE, ...){ h <- hist(x, plot=FALSE, ...) h$counts <- cumsum(h$counts) h$density <- cumsum(h$density) h$itensities <- cumsum(h$itensities) if(plot) plot(h) h } x <- rnorm(100, 15, 5) hist.cum(x) hist(x, add=TRUE, col="lightseagreen") # lines (density(x), add = TRUE, col="red") 回答1: Offered without explanation: ## Make some sample data x <- sample(0:30, 200,

two-way density plot combined with one way density plot with selected regions in r

大城市里の小女人 提交于 2019-11-26 15:14:20
问题 # data set.seed (123) xvar <- c(rnorm (1000, 50, 30), rnorm (1000, 40, 10), rnorm (1000, 70, 10)) yvar <- xvar + rnorm (length (xvar), 0, 20) myd <- data.frame (xvar, yvar) # density plot for xvar upperp = 80 # upper cutoff lowerp = 30 # lower cutoff x <- myd$xvar plot(density(x)) dens <- density(x) x11 <- min(which(dens$x <= lowerp)) x12 <- max(which(dens$x <= lowerp)) x21 <- min(which(dens$x > upperp)) x22 <- max(which(dens$x > upperp)) with(dens, polygon(x = c(x[c(x11, x11:x12, x12)]), y =