2012-05-28 24 views
5

Estoy usando gnuplot para generar gráficos para múltiples puntos de referencia.
Para cada punto de referencia, tengo muchas configuraciones para trazar. Quiero trazar una tasa de acierto del gráfico (mi eje y) frente al punto de referencia (eje x). Habrá múltiples columnas para cada punto de referencia diferenciadas por su color.gnuplot para agrupar múltiples barras

He generado el mismo tipo de gráficos hace algún tiempo utilizando algún script de python, pero no sé cómo hacerlo en gnuplot.

+0

Podemos ver una muestra de sus datos? ¿Están los puntos de referencia listados numéricamente o por nombre en su archivo de datos? – andyras

Respuesta

16

estos datos en bruto, 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 

Con este código:

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 

Proporciona la siguiente histograma:

gnuplot histogram

Pero se recomienda usar R de los cuales sintaxis es la forma más fácil de leer:

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

Además, proporciona una salida ligeramente más bonita:

R histogram

+0

hey the gnu script funcionó. Gracias. ¿Qué significa el comando title col? –

+0

No tengo ni idea: D Aparentemente, significa 'título del encabezado' y muestra el primer elemento de la fila. –

+0

¿Podemos agregar una barra de error a esta figura? – Ashkan

Cuestiones relacionadas