Gnuplot Polar Coodinates Histogram

耗尽温柔 提交于 2021-01-27 18:15:02

问题


I have a data file file.dat with three columns (radio, angle, Temperature) for points in the plane, and I want to plot this data as a histogram using polar coordenates and color maps, like in the figure below but using gnuplot. I can create a histogram.dat file with the values of the bins that I want but I don't know how to plot it in gnuplot


回答1:


To my knowledge there is no right-away "polar heatmap" plotting style in gnuplot (but I could be wrong, at least, I haven't seen an example on the demo page). Hence, you have to implement it yourself.

Basically, for each datapoint you have to plot a filled segment. Therefore, for each datapoint you have to create points on the circumference of this single segment. Then you can plot this segment with filledcurves and a specific color.

Assumptions:

  • data is in a regular grid/steps in angle (astep) and radius (rstep).
  • data is in a datablock (how to get it from a file into a datablock, see gnuplot: load datafile 1:1 into datablock)
  • separators are whitespaces
  • no header lines

Further optimization potential:

  • automatic extraction of astep and rstep.

I hope you can adapt the code to your needs.

Code:

### workaround for polar heatmap
reset session

set size square
set angle degrees
unset border
unset tics
set cbtics
set polar
set border polar
unset raxis

# create some test data
f(a,r) = r*cos(a) * r*sin(a) + rand(0)*100
set print $Data
    do for [a=0:350:10] {
        do for [r=1:20] {
            print sprintf("%g %g %g",a,r,f(a,r))
        }
    }
set print

astep = 10
rstep = 1

# create the segments for each datapoint
set print $PolarHeatmap
    do for [i=1:|$Data|] {
        a = real(word($Data[i],1))
        r = real(word($Data[i],2))
        c = real(word($Data[i],3))
        do for [j=-5:5] {
            print sprintf("%g %g %g",a+j*astep/10., r-0.5*rstep, c)
        }
        do for [j=5:-5:-1] {
            print sprintf("%g %g %g",a+j*astep/10., r+0.5*rstep, c)
        }
        print ""
        print ""
    }
set print

set style fill noborder
set palette defined (0 "blue", 1 "grey", 2 "green")

plot $PolarHeatmap u 1:2:3 w filledcurves palette notitle
### end of code

Result:



来源:https://stackoverflow.com/questions/62437031/gnuplot-polar-coodinates-histogram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!