简体   繁体   中英

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: 在此处输入图像描述

    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:

在此处输入图像描述

  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, eg smooth over your data, is more data-doctoring than science.

Solution provided by Adriaan .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM