3D data contour ploting using a kde

Dude-N

I have two Arrays of positional Data (X,Y) and a corresponding 1D Array of Integers (Z) that weighs the positional Data. So my Data set looks like that:

X = [ 507, 1100, 1105, 1080, 378, 398, 373]
Y = [1047,  838,  821,  838, 644, 644, 659]
Z = [ 300,   55,   15,   15,  55,  15,  15] 

I want to use that Data to create a KDE thats equivalent to a KDE that gets only X and Y as input but gets the X and Y values Z times. To apply that KDE to a np.mgrid to create a contourplot.

I already got it working by just iterating over the arrays in a FOR Loop and adding Z times X and Y, but that looks to me like a rather inelegant Solution and I hope you can help me to find a better way of doing this.

JohanC

You could use the weights= parameter of scipy.stats.gaussian_kde:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np
from scipy import stats

X = [ 507, 1100, 1105, 1080, 378, 398, 373]
Y = [1047,  838,  821,  838, 644, 644, 659]
Z = [ 300,   55,   15,   15,  55,  15,  15]

kernel = stats.gaussian_kde(np.array([X, Y]), weights=Z)

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
xs, ys = np.mgrid[0:1500:30j, 0:1500:30j]
zs = kernel(np.array([xs.ravel(), ys.ravel()])).reshape(xs.shape)
ax.plot_surface(xs, ys, zs, cmap="hot_r", lw=0.5, rstride=1, cstride=1, ec='k')
plt.show()

resulting plot

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

d3 real time graph ploting using mysql and streaming sensor data

From Dev

Python/Matplotlib: 2d random walk with kde joint density contour in a 3d plot

From Dev

Python/Matplotlib: 2d random walk with kde joint density contour in a 3d plot

From Dev

2D Density Contour Plot with KDE instead of histogram in plotly

From Dev

Matplotlib separate 2D contour projection plots of 3D data

From Dev

Ploting 3D points from csv file, Python?

From Dev

Ploting point clouds using Matlab

From Dev

Contour plot for 3D vector

From Dev

3D histograms and Contour plots Python

From Dev

Why ploting data in ILNumerics produce the result that is not symmetry? (2D Plot)

From Java

Why QCustomPlot is too slow in ploting large data?

From Dev

Remove data labels when ploting and exporting graphs

From Dev

Ploting datetime data from pandas datetime

From Dev

ploting multiple data series with Macro in excel

From Dev

Shell script for ploting multiple graph using gnuplot

From Dev

using sapply in R for ploting side by side graph

From Dev

Efficiently ploting a table in csv format using Python

From Dev

"Invalid slice" when ploting using matplotlib

From Dev

Shell script for ploting multiple graph using gnuplot

From Dev

Plotting 3D trajectory from CSV data using matplotlib

From Dev

Generating a heat map using 3D data in matplotlib

From Dev

Contour plot from data in a vtk file using Python

From Dev

Contour plot from data in a vtk file using Python

From Dev

When ploting 3d scalar field with Matlab, why axis X exchanges with Y?

From Dev

Ploting solid of revolution in Python 3 (matplotlib maybe)

From Dev

ploting scatter plot with 2D list

From Dev

Matlab 2d contour plot in 3d

From Dev

Adding extra contour lines using matplotlib 2D contour plotting

From Java

Halcon - 3D equivalent of affine_trans_contour_xld

Related Related

  1. 1

    d3 real time graph ploting using mysql and streaming sensor data

  2. 2

    Python/Matplotlib: 2d random walk with kde joint density contour in a 3d plot

  3. 3

    Python/Matplotlib: 2d random walk with kde joint density contour in a 3d plot

  4. 4

    2D Density Contour Plot with KDE instead of histogram in plotly

  5. 5

    Matplotlib separate 2D contour projection plots of 3D data

  6. 6

    Ploting 3D points from csv file, Python?

  7. 7

    Ploting point clouds using Matlab

  8. 8

    Contour plot for 3D vector

  9. 9

    3D histograms and Contour plots Python

  10. 10

    Why ploting data in ILNumerics produce the result that is not symmetry? (2D Plot)

  11. 11

    Why QCustomPlot is too slow in ploting large data?

  12. 12

    Remove data labels when ploting and exporting graphs

  13. 13

    Ploting datetime data from pandas datetime

  14. 14

    ploting multiple data series with Macro in excel

  15. 15

    Shell script for ploting multiple graph using gnuplot

  16. 16

    using sapply in R for ploting side by side graph

  17. 17

    Efficiently ploting a table in csv format using Python

  18. 18

    "Invalid slice" when ploting using matplotlib

  19. 19

    Shell script for ploting multiple graph using gnuplot

  20. 20

    Plotting 3D trajectory from CSV data using matplotlib

  21. 21

    Generating a heat map using 3D data in matplotlib

  22. 22

    Contour plot from data in a vtk file using Python

  23. 23

    Contour plot from data in a vtk file using Python

  24. 24

    When ploting 3d scalar field with Matlab, why axis X exchanges with Y?

  25. 25

    Ploting solid of revolution in Python 3 (matplotlib maybe)

  26. 26

    ploting scatter plot with 2D list

  27. 27

    Matlab 2d contour plot in 3d

  28. 28

    Adding extra contour lines using matplotlib 2D contour plotting

  29. 29

    Halcon - 3D equivalent of affine_trans_contour_xld

HotTag

Archive