3D histogram with gnuplot or octave

后端 未结 5 518
余生分开走
余生分开走 2020-12-09 13:17

I would like to draw a 3D histogram (with gnuplot or octave) in order to represent my data. lets say that I have a data file in the following form:

2 3 4             


        
5条回答
  •  猫巷女王i
    2020-12-09 13:43

    Solution using only functions available in OCTAVE, tested with octave-online

    This solution generates a surface in a similar way to the internals of Matlabs hist3d function.

    In brief:

    • creates a surface with 4 points with the "height" of each value, which are plotted at each bin edge.
    • Each is surrounded by zeros, which are also plotted at each bin edge.
    • The colour is set to be based on the bin values and is applied to the 4 points and the surrounding zeros. (so that the edges and tops of the 'bars' are coloured to match the "height".)

    For data given as a matrix containing bin heights (bin_values in the code):

    Code

    bin_values=rand(5,4); %some random data
    
    bin_edges_x=[0:size(bin_values,2)]; 
    x=kron(bin_edges_x,ones(1,5));
    x=x(4:end-2);
    
    bin_edges_y=[0:size(bin_values,1)]; 
    y=kron(bin_edges_y,ones(1,5));
    y=y(4:end-2);
    
    mask_z=[0,0,0,0,0;0,1,1,0,0;0,1,1,0,0;0,0,0,0,0;0,0,0,0,0];
    mask_c=ones(5);
    z=kron(bin_values,mask_z);
    c=kron(bin_values,mask_c);
    
    surf(x,y,z,c)
    

    Output

    3dhist

提交回复
热议问题