Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D graphs of probability density functions in MATLAB

I want to create the 3D plot of the probability density functions of my variable. I have a matrix with dimensions 189x10000, where rows correspond to the time and columns are results of the simulation. Can somebody help me to create a density plot over time? I want my plot to look like this: enter image description here

    A = [1:185]';  % substitute for date vector
    K = linspace( -20, 20, 100);
    f = zeros(185,100);
    xi = zeros(185,100);
    r = normrnd(0,1,[185,10000]);
     for i=1:185

        [f(i,:),xi(i,:)] = ksdensity(r(I,:));

     end
    a = figure;
    meshc(A, K', f')
    datetick('x', 'yyyy')
    view(85, 50)
    set(gca, 'YLim', [-15, 10])
    set(gca, 'XLim', [A(1), A(end)])
    xlabel('Time')

With this code I get this:

enter image description here

like image 818
user13201583 Avatar asked Nov 06 '22 06:11

user13201583


1 Answers

  1. Replace random numbers with density distribution.

  2. If you want a finer grid, then use more points. Your actual data has 10-times as much, right? Otherwise this is as good as it gets; "improving" your plot, e.g. smooth over your data, is more data-doctoring than science.

Solution provided by Adriaan.

like image 68
Miscellaneous Avatar answered Nov 11 '22 06:11

Miscellaneous