ComdTeX

Gráficas

Un bloque :::plot dibuja una gráfica SVG. Puede graficar una o varias funciones matemáticas, o las columnas de un dataset con nombre; ambas formas comparten el mismo bloque y la misma leyenda.

Gráficas de funciones

La forma más simple define una función de x:

:::plot[Onda]
f(x) = sin(x)
range: [-3, 3]
:::

[Onda] es el título opcional de la gráfica. f(x) = sin(x) define una función con nombre; range: [-3, 3] fija el rango del eje x. Sin un range explícito, ComdTeX usa [-2π, 2π].

Un mismo bloque acepta varias funciones a la vez, cada una en su propia línea, y también una expresión anónima sin nombre:

:::plot[Comparación]
f(x) = sin(x)
g(x) = cos(x)
x^2 / 4
range: [-5, 5]
:::

Cada función se dibuja con un color distinto y aparece en la leyenda con su nombre (f, g) o, si es anónima, con la propia expresión.

Funciones soportadas

FunciónSignificado
sin, cos, tanTrigonométricas
asin, acos, atanTrigonométricas inversas
sinh, cosh, tanhHiperbólicas
expExponencial
log, log2, log10Logaritmo natural, base 2, base 10
sqrtRaíz cuadrada
absValor absoluto
ceil, floor, round, signRedondeo y signo

También se reconocen las constantes pi (o π) y e, y ^ o ** para potencias.

Graficando datos de un dataset

En lugar de una función, un bloque :::plot puede nombrar un dataset declarado con :::data (ver Tablas desde datos) y dibujar una serie por columna:

:::plot[Crecimiento por cepa]
@data:growth
x: time
y: (S1, S2, S3)
kind: line
error: sd
:::
DirectivaSignificado
@data:nombreReferencia al dataset declarado con :::data{#data:nombre}
x:Columna usada como eje x, por nombre de encabezado, letra de hoja de cálculo o índice
y:Columna o columnas para el eje y, entre paréntesis si son varias: (S1, S2, S3)
kind:Forma de la serie: line, scatter o bars
error:Columna con la incertidumbre; dibuja barras de error sobre cualquier kind

Las cuatro formas

line: una línea con un marcador en cada medición real.

:::plot[Temperatura]
@data:sensor
x: hora
y: temp_c
kind: line
:::

scatter: solo los marcadores, sin línea que los conecte.

:::plot[Dispersión]
@data:sensor
x: temp_c
y: humedad
kind: scatter
:::

bars: barras agrupadas por categoría.

:::plot[Rendimiento]
@data:cultivos
x: variedad
y: (kg_2024, kg_2025)
kind: bars
:::

Barras de error: se combinan con cualquiera de las tres formas anteriores mediante error:, que dibuja una barra vertical con topes sobre cada punto.

:::plot[Crecimiento con incertidumbre]
@data:growth
x: time
y: S1
kind: scatter
error: sd
:::

Reglas de selección

Omitir y: grafica todas las columnas del dataset excepto la de x y la de error, así que el caso común (una columna de tiempo y varias mediciones) no necesita ninguna directiva de columnas. Cuando la columna de x no es numérica (nombres de muestra, condiciones), ComdTeX la convierte automáticamente en categorías espaciadas de forma uniforme; esto es justamente lo que necesitan las barras para agruparse por variedad, condición o cepa en lugar de por un valor numérico. Los títulos de los ejes se toman directamente de los encabezados de las columnas usadas, así que no hace falta escribirlos a mano.

Colores, leyenda y exportación

Cada gráfica usa una paleta de seis colores que se reparte entre funciones y series de datos por igual, así que una gráfica que mezcla una curva ajustada con sus mediciones nunca reutiliza un color para ambas cosas. La leyenda combina funciones y series de datos en una sola lista, en el orden en que aparecen en el bloque.

Como cualquier otro diagrama de ComdTeX, la gráfica llega al PDF como una imagen: se rasteriza en “Compilar PDF”, “Exportar PDF” y “Exportar como .tex”, y no como el código fuente del bloque.

Plots

A :::plot block draws an SVG chart. It can plot one or more mathematical functions, or the columns of a named dataset; both forms share the same block and the same legend.

Function plots

The simplest form defines a function of x:

:::plot[Wave]
f(x) = sin(x)
range: [-3, 3]
:::

[Wave] is the plot’s optional title. f(x) = sin(x) defines a named function; range: [-3, 3] sets the x-axis range. Without an explicit range, ComdTeX uses [-2π, 2π].

A single block accepts several functions at once, each on its own line, plus an anonymous expression with no name:

:::plot[Comparison]
f(x) = sin(x)
g(x) = cos(x)
x^2 / 4
range: [-5, 5]
:::

Each function is drawn in a distinct color and appears in the legend under its name (f, g) or, if anonymous, under the expression itself.

Supported functions

FunctionMeaning
sin, cos, tanTrigonometric
asin, acos, atanInverse trigonometric
sinh, cosh, tanhHyperbolic
expExponential
log, log2, log10Natural, base-2 and base-10 logarithm
sqrtSquare root
absAbsolute value
ceil, floor, round, signRounding and sign

The constants pi (or π) and e are also recognized, along with ^ or ** for powers.

Plotting data from a dataset

Instead of a function, a :::plot block can name a dataset declared with :::data (see Tables from data) and draw one series per column:

:::plot[Growth by strain]
@data:growth
x: time
y: (S1, S2, S3)
kind: line
error: sd
:::
DirectiveMeaning
@data:nameReference to the dataset declared with :::data{#data:name}
x:Column used as the x axis, by header name, spreadsheet letter or index
y:Column or columns for the y axis, in parentheses when there is more than one: (S1, S2, S3)
kind:Series shape: line, scatter or bars
error:Column holding the uncertainty; draws error bars on top of any kind

The four shapes

line: a line with a marker at every real measurement.

:::plot[Temperature]
@data:sensor
x: hour
y: temp_c
kind: line
:::

scatter: markers only, with no connecting line.

:::plot[Scatter]
@data:sensor
x: temp_c
y: humidity
kind: scatter
:::

bars: bars grouped by category.

:::plot[Yield]
@data:crops
x: variety
y: (kg_2024, kg_2025)
kind: bars
:::

Error bars: combine with any of the three shapes above via error:, which draws a vertical capped bar over each point.

:::plot[Growth with uncertainty]
@data:growth
x: time
y: S1
kind: scatter
error: sd
:::

Selection rules

Leaving out y: plots every column in the dataset except the x column and the error column, so the common case (a time column plus several measurements) needs no column directives at all. When the x column is not numeric (sample names, conditions), ComdTeX turns it into evenly spaced categories automatically; that is exactly what bars need to group by variety, condition or strain instead of by a numeric value. Axis titles come straight from the headers of the columns used, so there is nothing to type by hand.

Colors, legend and export

Every plot uses a six-color palette that is shared evenly between functions and data series, so a plot mixing a fitted curve with its measurements never reuses one color for both. The legend merges functions and data series into a single list, in the order they appear in the block.

Like every other ComdTeX diagram, the plot reaches the PDF as an image: it is rasterized in “Compile PDF”, “Export PDF” and “Export as .tex”, never as the block’s source code.