【问题标题】:"Pie chart"-like data point for scatter diagram in GnuplotGnuplot 中散点图的“饼图”式数据点
【发布时间】:2020-12-07 09:38:50
【问题描述】:

我进入了数据分析阶段,我需要在单个图中显示多个维度,以便更好地强调相关性。为每个数据点放置一个饼图将是最好的方法。在此附上我在以下位置找到的图:https://andypope.info/charts/piedatamarkers.htm

如何在 Gnuplot 5.2 中生成这样的图表?我知道标准绘图类型是不可能的,我正在寻找一种解决方法。我会继续循环并使用 Python 制作一个生成这样一个情节的脚本。

【问题讨论】:

  • 您的数据是什么样的?你检查过这个gnuplot.sourceforge.net/demo_5.4/circles.html 那里的例子也应该在 gnuplot 5.2 中工作
  • 我没有固定的数据结构,它很灵活。目前,我使用 Python 对数据进行预处理,以在六列中列出圆的位置、半径、角度和颜色。这远非理想。

标签: gnuplot pie-chart datapoint


【解决方案1】:

这里是 here 提到的例子的一个稍微简化的变体,尤其是 plot 命令更短更清晰。

饼图的半径要么是固定的:value>0 in column3,要么是自动的:value0xRRGGBB 颜色。此示例可作为进一步改进和调整的起点。

代码:

### 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

结果:

【讨论】:

  • 谢谢,@theozh!这是一个非常巧妙的解决方案!正是我想要实现的目标,但使用两个或三个嵌套循环无法完成。我认为您的解决方案应该是一个教科书示例!
猜你喜欢
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多