음의 좌표가 있는 ybar 누적 플롯

음의 좌표가 있는 ybar 누적 플롯

양수 좌표와 음수 좌표가 혼합된 ybar를 사용할 때 원하는 답을 찾을 수 없는 것 같습니다.

\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[ybar stacked]
      \addplot[green,fill=green] coordinates { (1, 3) (2, 3) (3,3) (4,3) };
      \addplot[red,fill=red]     coordinates { (1,-4) (2,-4) (3,4) (4,4) };
    \end{axis}
  \end{tikzpicture}
\end{figure}

왼쪽 두 개의 막대가 녹색 막대 뒤에 숨겨져 있지만 좌표에 있는 대로 4단위 길이의 빨간색 막대를 모두 가져오고 싶습니다. 이에 대한 해결책이 있습니까? ( \addplot위 코드에서 호출 순서를 변경해도 문제가 해결되지 않습니다.)

답변1

나는 플롯 스타일을 사용하는 것을 제안하고 싶지만 ybar stacked구성 요소가 수평으로 오프셋되어 있습니다."폭포형 차트". 이는 양수 및 음수 기여도가 최종 값에 어떻게 추가되는지 보여주는 데 효과적입니다. (Y축 아래에 음수 구성요소를 그리는 것보다 낫습니다. 그러면 전체 길이가 더 길어질 수 있습니다.)

막대 사이에 커넥터를 그리려면 를 사용하여 새 마커를 정의해야 합니다 \pgfdeclareplotmark.

\documentclass{article}
\usepackage{pgfplots}

\pgfdeclareplotmark{waterfall bridge}{\pgfpathmoveto{\pgfpoint{-13pt}{0pt}}\pgfpathlineto{\pgfpoint{13pt}{0pt}}\pgfusepathqstroke}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
        ybar stacked,
        bar width=10pt,
        axis lines*=middle,
        axis on top=false,
        xtick=data,
        enlarge y limits=0.2,
        after end axis/.code={
            \node at ({rel axis cs:0,0}|-{axis cs:0,0}) [anchor=east] {0};
        }
    ]
      \addplot[
        fill=cyan,
        draw=none,
        bar shift=-8pt,
        mark options={
            gray,
            thick,
            dashed
        },
        mark=waterfall bridge
      ] coordinates { (1, 3) (2, 3) (3,3) (4,3) };
      \addplot[
        fill=orange,
        draw=none,
        bar shift=8pt
      ] coordinates { (1,-4) (2,-4) (3,4) (4,4) };
    \end{axis}
  \end{tikzpicture}


\end{document}

답변2

나 역시 이 문제에 여러 번 부딪혔다. 내 (물론 추악한) 해결 방법은 별도의 환경에서 음수 막대를 만드는 것입니다 axis. 두 축의 치수와 막대 너비가 동일한지 확인해야 하고 두 번째 축에서 축 선을 제거해야 하기 때문에 차선책이지만 원하는 효과를 얻습니다.

답변3

우리도 같은 문제가있었습니다.

우리가 생각해낸 해결책은 상대적으로 방해가 되지 않습니다. 라텍스 코드는 추가 특수 태그 없이 동일하게 유지되지만 음수 값의 x 좌표는 약간 변경됩니다.

기본적으로 모든 x 좌표는 별도로 쌓이기 때문에 양수는 1, 2, 3 등에 표시되고 음수는 0.999, 1.999, 2.999 등에 표시됩니다.

사람의 눈에는 서로 바로 위에 있는 것처럼 보이지만(그렇지 않은 경우 9를 더 추가) 쌓기 위해 라텍스는 별도로 쌓습니다.

하루에 긍정적이고 부정적인 에너지
(원천:pnpscada.com)

다음은 .tex 타일의 코드 추출입니다.

. . .
\begin{axis}[width=20cm, height=9.75cm,
scaled ticks=false,%
%bar width=5pt,
xmin=-0.15,
xtick={1,...,\days},
xmax=\the\value{daysp}.15,
ylabel=energy in \si{kWh},
xlabel = date,
%xlabel= {\yearnow},
%xtick align=center,
%xticklabel style={rotate=90,anchor=east},
grid=major,
legend cell align=left,
%legend entries={baseline,target,trend,low demand--off-peak,low demand--standard,low demand--peak,high demand--off-peak,high demand--standard,high demand--peak},
legend style = {area legend,legend columns = 4,
%legend title = legend,
at={(0.5,-0.12)},
anchor=north},
%legend entries={baseline,target,trend,low demand--off-peak,low demand--standard,low demand--peak,high demand--off-peak,high demand--standard,high demand--peak},
title={{\month} {\yearnow} consumption for \meter},
%title style={at={(0.5,1)}},
ybar stacked,
set layers
]
. . .
\trend ;
\addplot[draw=black, fill=color8, forget plot] table [x=x,y=v8]{Month.csv};
\addplot[draw=black, fill=color1, forget plot] table [x=x,y=v1]{Month.csv};
\addplot[draw=black, fill=color12, forget plot] table [x=x,y=v12]{Month.csv};
\addplot[draw=black, fill=color6, forget plot] table [x=x,y=v6]{Month.csv};
\addplot[draw=black, fill=color9, forget plot] table [x=x,y=v9]{Month.csv};
 \addplot[draw=black, fill=color3, forget plot] table [x=x,y=v3]{Month.csv};
. . .

유사한 Month.csv 파일에서 추출한 내용입니다(그림과 완전히 동일하지는 않지만 아이디어를 보여줍니다)(열은 탭으로 구분됩니다).

x   v7  v8  v1  v2  v11 v12 v5  v6  v9  v10 v3  v4  target
. . .
6.25    0   0   0   0   0   0   0   0   0   0   0   0   1682.16
6.5 0   0   0   0   0   0   0   0   0   0   0   0   1682.16
6.999   0   0   -30 0   0   0   0   0   0   0   -54.500 0   1682.16
7   0   0   0   200 0   0   0   0   0   0   0   1190.000    1682.16
7.25    0   0   0   0   0   0   0   0   0   0   0   0   1682.16
7.5 0   0   0   0   0   0   0   0   0   0   0   0   1682.16
7.999   0   0   -50 0   0   0   0   0   0   0   -93.000 0   1682.16
8   0   0   0   400 0   0   0   0   0   0   0   1068.000    1682.16
. . .

관련 정보