"Pie chart"-like data point for scatter diagram in Gnuplot

350 views Asked by At

I got to the stage in data analysis, where I need to show multiple dimensions in a single plot in order to better emphasize correlations. Placing a pie-chart for every data point would be the best way to go. Appended here a figure I found at: https://andypope.info/charts/piedatamarkers.htm

How can I produce such a graph in Gnuplot 5.2? I know it is not possible by standard plot types, I am looking for a workaround. I would go along loops and using Python to make a script that generates such a plot.

enter image description here

1

There are 1 answers

1
theozh On BEST ANSWER

Here is a slightly simplified variation of the example mentioned here, especially the plot command is shorter and clearer.

The radius of the pie-charts are either fixed: value>0 in column3 or or automatic: value<0 in column3. In the latter case, the area of the circle is proportional to the total sum of the columns. The arc colors can be chosen as 0xRRGGBB colors. This example may serve as a starting point for further improvements and adaptions.

Code:

### plot with piecharts as points
reset session

$Data <<EOD
# x y    r  c1   c2   c3   c4   c5
2   16  -1  1.0  1.0  1.0  0.5  3.0
3    5  -1  0.8  0.7  0.5  0.9  0.8
7   15  -1  1.5  1.3  1.4  2.1  1.2
11  10  -1  5.6  8.7  3.1  3.1  9.4
12  19  -1  1.7  2.5  3.3  1.0  0.9
17   3  -1  4.1  5.1  1.4  0.5  5.3
19  14  -1  0.1  0.2  0.3  0.4  0.5
22  17  -1  2.1  2.2  3.2  4.2  1.5
EOD

stats $Data nooutput    # get the number of columns
colMax = STATS_columns
colMin = 4              # starting column for data
Scale = 0.3             # general scaling of circles
set angle degrees

Part(i) = sum [col=colMin:i] column(col)
Total(n) = Part(colMax)
Radius(r) = Scale * (r<0 ? sqrt(Total(0)) : r)    # radius<0: automatic calculation, proportional to sqrt
ArcStart = 90                                     # pie-chart start angle: 90=twelve o'clock
ArcDir = -1                                       # direction: -1 = clockwise, 1 = counterclockwise
ArcFrom(i) = ArcDir*Part(int(i)+(ArcDir<0?0:-1))/Total(0)*360 + ArcStart
ArcTo(i)   = ArcDir*Part(int(i)+(ArcDir<0?-1:0))/Total(0)*360 + ArcStart
ArcColor(i) = int(word("0xff0000 0x00ff00 0x0000ff 0xff00ff 0xffff00",i-colMin+1))

set xrange[0:25]
set yrange[0:25]
set grid xtics, ytics
set style fill solid 0.5 noborder

plot for [j=colMin:colMax] $Data u 1:2:(Radius($3)):(ArcFrom(j)):(ArcTo(j)):(ArcColor(j)) w circle lc rgb var notitle
### end of code

Result:

enter image description here