
Ich habe folgende CSV-Datei:
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
wessen Name ist file
.
Der folgende Code
\begin{tikzpicture}
\begin{axis}[black,ylabel=Frequency, legend pos=outer north east]
\addplot table[col sep=comma] {file.csv};
\end{axis}
\end{tikzpicture}
Das ist in Ordnung, aber ich möchte stattdessen einen stückweise konstanten Graphen zeichnen. Wenn wir uns beispielsweise ansehen file
, haben wir
1,36
entspricht einer konstanten Linie zwischen 1 und 2, mit konstanter Ordinate 36,
2,22
entspricht einer konstanten Linie zwischen 2 und 3, mit konstanter Ordinate 22 und so weiter.
Antwort1
(Ich erweitere meinen Kommentar hier zu einer vollständigen Antwort.)
Sie können die const plot
Option für verwenden \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}