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:

    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:

Replace random numbers with density distribution.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With