gnuplot 对多个条进行分组 [英] gnuplot to group multiple bars

查看:29
本文介绍了gnuplot 对多个条进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 gnuplot 为多个基准生成图表.
对于每个基准,我有许多配置要绘制.我想绘制一个图表命中率(我的 y 轴)与基准(x 轴).每个基准将有多个列,按颜色区分.

I am using gnuplot to generate graphs for multiple benchmarks.
For each benchmark I have many configurations to plot. I want to plot a graph hit-rate(my y-axis) vs benchmark(x-axis). There will be multiple columns for each benchmark differentiated by their color.

前段时间我使用一些 python 脚本生成了相同类型的图形,但我不知道如何在 gnuplot 中执行此操作.

I generated the same type of graphs some time back using some python script, but I don't know how to do this in gnuplot.

推荐答案

这个原始数据,languages.data:

Title   C   C++ Java    Python
"Writing code"  6   4   10  1
"Understanding code"    6   3   4   1
"Generating prime numbers"  3   1   2   10

使用此代码:

set title "Benchmarks"
C = "#99ffff"; Cpp = "#4671d5"; Java = "#ff0000"; Python = "#f36e00"
set auto x
set yrange [0:10]
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set xtic scale 0
# 2, 3, 4, 5 are the indexes of the columns; 'fc' stands for 'fillcolor'
plot 'languages.data' using 2:xtic(1) ti col fc rgb C, '' u 3 ti col fc rgb Cpp, '' u 4 ti col fc rgb Java, '' u 5 ti col fc rgb Python

提供以下直方图:

但我建议使用 R ,其中语法更具可读性:

But I would suggest using R of which syntax is way more readable:

library(ggplot2)
# header = TRUE ignores the first line, check.names = FALSE allows '+' in 'C++'
benchmark <- read.table("../Desktop/gnuplot/histogram.dat", header = TRUE, row.names = "Title", check.names = FALSE)
# 't()' is matrix tranposition, 'beside = TRUE' separates the benchmarks, 'heat' provides nice colors
barplot(t(as.matrix(benchmark)), beside = TRUE, col = heat.colors(4))
# 'cex' stands for 'character expansion', 'bty' for 'box type' (we don't want borders)
legend("topleft", names(benchmark), cex = 0.9, bty = "n", fill = heat.colors(4))

此外,它提供了更漂亮的输出:

Furthermore it provides a slightly prettier output:

这篇关于gnuplot 对多个条进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆