How to plot (x,y,z) points showing their density

后端 未结 1 1508
执念已碎
执念已碎 2021-01-05 00:43

My data file is a set of (x,y,z) points located around the axis origin. They represent points where a kind of measure has failed. These points are in this link.

Gnup

相关标签:
1条回答
  • 2021-01-05 01:20

    @user1993416, I guess you can do something with gnuplot. You might need to play with the parameter Delta. With my 8 year old computer 1000 points need approx. 2 minutes.

    The followig code:

    ### 3D density plot
    reset session
    set term wxt
    
    N = 1000      # number of datapoints
    Delta = 2    # half boxwidth
    
    TimeStart = time(0.0)
    # create dummy some dummy data
    set samples N
    set table $Data
        plot '+' u (invnorm(rand(0))):(invnorm(rand(0))):(invnorm(rand(0))) with table
    unset table
    
    # put the datafile/dataset into arrays
    stats $Data nooutput
    RowCount = STATS_records
    array ColX[RowCount]
    array ColY[RowCount]
    array ColZ[RowCount]
    array ColC[RowCount]
    do for [i=1:RowCount] {
    set table $Dummy
        plot $Data u (ColX[$0+1]=$1,0):(ColY[$0+1]=$2,0):(ColZ[$0+1]=$3,0) with table
    unset table
    }
    
    # look at each datapoint and its sourrounding
    do for [i=1:RowCount] {
        print sprintf("Datapoint %g of %g",i,RowCount)
        x0 = ColX[i]
        y0 = ColY[i]
        z0 = ColZ[i]
        # count the datapoints with distances <Delta around the datapoint of interest
        set table $Occurrences
            plot $Data u ((abs(x0-$1)<Delta) & (abs(y0-$2)<Delta) & (abs(z0-$3)<Delta) ? 1 : 0):(1) smooth frequency
        unset table
        # extract the number from $Occurrences which will be used to color the datapoint
        set table $Dummmy
            plot $Occurrences u (c0=$2,0):($0) every ::1::1 with table
        unset table
        ColC[i] = c0
    }
    
    # put the arrays into a dataset again
    set print $Data
    do for [i=1:RowCount] {
        print sprintf("%g\t%g\t%g\t%g",ColX[i],ColY[i],ColZ[i],ColC[i])
    }
    set print
    
    TimeEnd = time(0.0)
    print sprintf("Duration: %.3f sec",TimeEnd-TimeStart)
    
    set palette rgb 33,13,10
    splot $Data u 1:2:3:4 w p ps 1 pt 7 lc palette z notitle
    
    set terminal gif animate delay 30
    set output "Density.gif"
    Amin = 40
    Amax = 60
    AFrames = 25
    do for [i=0:AFrames] {
        print sprintf("Frame %g, Angle: %.1f", i, sin(2*pi*i/AFrames)*(Amax-Amin)+Amin)
        set view 45,(sin(2*pi*i/AFrames)*(Amax-Amin)+Amin)
        replot
    }
    set output
    

    should result in:

    0 讨论(0)
提交回复
热议问题