
Tengo el siguiente archivo csv:
1,36
2,22
3,13
4,8
5,7
6,2
7,1
8,7
9,12
10,5
11,6
12,2
13,7
14,4
15,4
16,1
17,2
18,1
19,1
20,2
21,2
22,1
23,1
24,1
25,1
26,1
27,2
28,0
29,0
30,0
31,0
32,1
33,0
34,0
35,0
36,1
cuyo nombre es file
.
El siguiente código
\begin{tikzpicture}
\begin{axis}[black,ylabel=Frequency, legend pos=outer north east]
\addplot table[col sep=comma] {file.csv};
\end{axis}
\end{tikzpicture}
Está bien, pero me gustaría dibujar en su lugar un gráfico constante por partes. Por ejemplo, si miramos file
, tenemos
1,36
corresponde a una recta constante entre 1 y 2, con ordenada constante 36,
2,22
corresponde a una recta constante entre 2 y 3, con ordenada constante 22 y así sucesivamente.
Respuesta1
(Extiendo mi comentario a una respuesta completa aquí).
Puedes usar la const plot
opción para \addplot
.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{filecontents*}{file.csv}
1,36
2,22
3,13
4,8
5,7
6,2
7,1
8,7
9,12
10,5
11,6
12,2
13,7
14,4
15,4
16,1
17,2
18,1
19,1
20,2
21,2
22,1
23,1
24,1
25,1
26,1
27,2
28,0
29,0
30,0
31,0
32,1
33,0
34,0
35,0
36,1
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ylabel=Frequency]
\addplot+[const plot] table[col sep=comma] {file.csv};
\end{axis}
\end{tikzpicture}
\end{document}