我想制作一个像这张图片一样的 ybar 图(抱歉我的绘画技巧不好 ;))
这样,条形图就会从负变为正或从正变为负,并且条形图的长度应记为每条条形图中心的一条线,因此就像对向量求和一样。我尝试使用瀑布图,但它与此处的图片不同。也许有人可以帮助我?
这里有一个简短的代码示例:带有减号和加号以及 2 轴环境的条形图:类似这样的情况,但如果一个条形图进入减号,则该条形图应从最后一个条形图的末尾开始,一直到减号
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={test1,test2},
xtick=data,
x tick label style={rotate=-45,anchor=west},
xticklabel shift={.5cm},
ybar stacked,
bar width=6mm,
ymin=-50,
ymax=120,
legend style={
at={(1,0.5)},
anchor=north west,draw=none },
restrict y to domain*=:0, % negative values
y=1pt, % important workaround!
axis x line*=middle,
axis y line=left,
axis on top=false,
enlarge x limits=0.2,
nodes near coords,
ybar legend,
]
\addplot coordinates {(test1,-11)};
\addplot coordinates {(test1,80)};
\legend{blue, red}
\end{axis}
\begin{axis}[
symbolic x coords={test1,test2},
xtick=data,
x tick label style={rotate=-45,anchor=west},
xticklabel shift={.5cm},
ybar stacked,
bar width=6mm,
ymin=-50,
ymax=120,
legend style={
at={(1,0.5)},anchor=north west,draw=none },
restrict y to domain*=0:, % positive values
y=1pt, % important workaround!
axis x line*=middle,
axis y line=left,
axis on top=false,
enlarge x limits=0.2,
nodes near coords,
ybar legend,
]
\addplot coordinates {(test1,-11)};
\addplot coordinates {(test1,80)};
\legend{blue, red}
\end{axis}
\end{tikzpicture}