
次の 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
名前は ですfile
。
次のコード
\begin{tikzpicture}
\begin{axis}[black,ylabel=Frequency, legend pos=outer north east]
\addplot table[col sep=comma] {file.csv};
\end{axis}
\end{tikzpicture}
それはそれでいいのですが、代わりに区分定数グラフを描きたいと思います。例えば、 を見るとfile
、
1,36
1と2の間の一定の線に対応し、縦座標は36で一定である。
2,22
2 と 3 の間の一定の線に対応し、一定の縦座標は 22 などになります。
答え1
(私のコメントを完全な回答までここに記載します。)
const plot
オプションを使用できます\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}