부록

부록

시간을 표시하고 싶어요와이중심선. 이 코드를 개발했지만 출력이 표시되지 않습니다.

\usepackage{filecontents}
\begin{filecontents}{mwe.csv}
Time,a,b
 00:00,0,10
 10:30,6,4
 11:30,5,5
 12:30,3,7
 13:30,2,8
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
Time coordinates in=x, 
xticklabel={\begin{turn}{45}\hour.\minute \end{turn}\\},
x tick label style={align=center},
ymajorgrids,
xmin={00:00},
xmax={21:30},
ymin=00:00,
legend pos=north west,]
\addplot [ycomb,color=blue] table [col sep=comma,trim cells=true,y=a] {mwe.csv}; \addlegendentry{a}
\addplot [ycomb,color=red]  table [col sep=comma,trim cells=true,y=b] {mwe.csv}; \addlegendentry{b}
\end{axis}
\end{tikzpicture}
\end{document}

답변1

라이브러리를 사용하려는 것처럼 보이지만 dateplot매뉴얼에 설명된 대로필요시간뿐만 아니라 날짜도 지정하려면:

여기에 이미지 설명을 입력하세요

date coordinates in=x또한 가 아니라 이어야 한다는 점에 유의하십시오 Time coordinates in=x. 입력 파일에 날짜를 추가하고 그에 따라 xmin/ 값을 조정한 후 xmax:

\begin{filecontents}{mwe.csv}
Time,a,b
2020-1-1 00:00,0,10
2020-1-1 10:30,6,4
2020-1-1 11:30,5,5
2020-1-1 12:30,3,7
2020-1-1 13:30,2,8
\end{filecontents}

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x, 
xticklabel={\hour.\minute},
x tick label style={align=center,rotate=45},
ymajorgrids,
xmin={2020-1-1 00:00},
xmax={2020-1-1 21:30},
legend pos=north west
]

\addplot [ycomb,color=blue] table [col sep=comma,y=a] {mwe.csv};
 \addlegendentry{a}
\addplot [ycomb,color=red]  table [col sep=comma,y=b] {mwe.csv};
 \addlegendentry{b}
\end{axis}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

부록

반면에 기호 1의 답변을 사용하려는 경우TikZ 및 pgfplots를 사용하여 날짜 및 시간 플롯을 만드는 방법그런 다음 아래 코드를 참조하세요. 질문에 이것을 언급했다면 좋았을 것입니다 (frougon의 요청에 따라 더 많은 정보를 제공 할 때까지 기다릴 수 있었을 것 같지만 ...).

스타일에 올바른 이름을 사용했는지 확인해야 합니다. 기호 1의 코드는 을 정의 time coordinates in합니다 Time coordinates in. 이는 대소문자를 구분하므로 스타일 정의와 사용 모두에서 동일한 대소문자를 사용해야 합니다.

범례가 비어 있다는 점에 유의하세요. Stefan Pinnow는 ycomb플롯 에 대한 보다 유용한 범례를 얻는 방법을 보여줍니다 .https://tex.stackexchange.com/a/357469/.

\begin{filecontents*}{mwe.csv}
Time,a,b
00:00,0,10
10:30,6,4
11:30,5,5
12:30,3,7
13:30,2,8
\end{filecontents*}

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

% the following is from https://tex.stackexchange.com/a/288225/
\def\pgfplotslibdateplothour:minutetofloat#1:#2.{
    \pgfmathparse{#1+#2/60}
}
\def\pgfplotslibdateplofloattothour:minute#1.{
    \pgfmathsetmacro\hour{int(floor(#1))}
    \pgfmathsetmacro\minute{int((#1-\hour)*60)}
    \ifnum\hour<10\edef\hour{0\hour}\fi
    \ifnum\minute<10\edef\minute{0\minute}\fi
}
\pgfplotsset{
    /pgfplots/time coordinates in/.code={%
        \pgfkeysdef{/pgfplots/#1 coord trafo}{%
            \pgfplotslibdateplothour:minutetofloat##1.
        }
        \pgfkeysdef{/pgfplots/#1 coord inv trafo}{
            \pgfplotslibdateplofloattothour:minute##1.
        }
    }
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
time coordinates in=x,
xticklabel={\hour.\minute},
x tick label style={align=center,rotate=45},
ymajorgrids,
xmin={00:00},
xmax={21:30},
legend pos=north west,
]
\addplot [ycomb, draw=blue] table [col sep=comma,trim cells=true,y=a] {mwe.csv};
\addlegendentry{a}

\addplot [ycomb,color=red]  table [col sep=comma,trim cells=true,y=b] {mwe.csv};
\addlegendentry{b}

\end{axis}
\end{tikzpicture}
\end{document}

답변2

frougon이 언급했듯이 코드는 완전하지 않습니다. 아마도 다음은 올바른 방향으로 진행될 것입니다.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{dateplot}
\usepackage{filecontents}
\begin{filecontents}{mwe.csv}
Time,a,b
 00:00,0,10
 10:30,6,4
 11:30,5,5
 12:30,3,7
 13:30,2,8
\end{filecontents}

\usepackage{xfp}
% from https://tex.stackexchange.com/a/445564/121799
\def\marmottimeparseaux#1:#2xxx{#1* 60 + #2}
\ExplSyntaxOn
\cs_new:Nn \marmot_timeparse:n { \marmottimeparseaux #1xxx }
\newcommand\TimeParse[1]{\exp_args:Nf\marmot_timeparse:n {#1}}
\ExplSyntaxOff
\pgfplotsset{
    /pgfplots/ycomb legend/.style={
        /pgfplots/legend image code/.code={%
            \path (0cm,0cm) (0.6cm,0.3cm);  
            \draw [#1] (0.3cm,-0.1cm) -- (0.3cm,0.2cm);},
    },
}


\begin{document}
\begin{tikzpicture}
\begin{axis}[ycomb,ycomb legend,
xticklabel={\pgfmathtruncatemacro{\myhour}{\tick/60}%
\pgfmathtruncatemacro{\myminute}{\tick-\myhour*60}%
\myhour:\myminute},
x tick label style={align=center},
ymajorgrids,
xmin=\TimeParse{00:-10},
xmax=\TimeParse{21:30},
ymin=0,
legend pos=north west,]
\addplot [color=blue,xshift=-2pt] table [col sep=comma,y=a,
    x expr=\TimeParse{\thisrow{Time}}] {mwe.csv};   
\addlegendentry{a}
\addplot [ycomb,color=red,xshift=2pt]  table [col sep=comma,trim cells=true,y=b,
x expr=\TimeParse{\thisrow{Time}}] {mwe.csv}; 
\addlegendentry{b}
\end{axis}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보