我遇到了一个问题,但我不知道该如何解决:(
请你帮助我好吗?
\documentclass[a4paper]{report}
enter code here\usepackage{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{calc}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}
\pgfplotsset{
show sum on top/.style={
/pgfplots/scatter/@post marker code/.append code={%
\path let \p1=($(normalized axis cs:%
\pgfkeysvalueof{/data point/x},%
\pgfkeysvalueof{/data point/y})%
-(normalized axis cs:\pgfkeysvalueof{/data point/x},0)$)
in node[
at={(normalized axis cs:%
\pgfkeysvalueof{/data point/x},%
\pgfkeysvalueof{/data point/y})%
},
anchor={-90*sign(\y1)},yshift={sign(\y1)*2pt}
]
{\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}};
},
},
}
\begin{document}
\pgfplotstableread{
Year OneCol SecCol ThirdCol ForthCol FifthCol SixthCol
1 6.58E-08 1.44E-08 5.42E-08 4.02E-08 2.30E-08 -6.02E-09
2 2.42E-09 3.17E-10 1.19E-09 8.85E-10 5.07E-10 -1.22E-10
3 1.53E-08 3.17E-10 1.19E-09 8.85E-10 5.54E-10 6.88E-10
}\datatable
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
width=0.9*\textwidth,
bar width=0.26cm,
tick label style={/pgf/number format/1000 sep=,font=\footnotesize},
ybar stacked,
stack negative=on previous, %<- moved down
bar width=1em,
ymin=-5.00E-08,
axis on top,
ymax=2.50E-07,
ymajorgrids = true,
enlarge x limits={true, abs value=0.75},
height=8cm,
nodes near coords={},
legend style={
at={(1.1,0.5)},
anchor=west,
draw=none },
xtick=data,
xticklabels={Cenário Um, Cenário Dois, Cenário Três}
]
\addplot [fill=cyan!70,draw=black!70] table [y index=1] {\datatable};
\addplot [fill=green!90,draw=black!70] table [y index=2] {\datatable};
\addplot [fill=teal!90,draw=black!70]table [y index=3] {\datatable};
\addplot [fill=violet!90,draw=black!70]table [y index=4] {\datatable};
\addplot [fill=lime!90,draw=black!70]table [y index=5] {\datatable};
\addplot [fill=magenta!90,draw=black!70]table [y index=6] {\datatable};
\legend{Bateria, Estrutura,Motor,Pneu,Uso,Final de Vida}
\end{axis}
\end{tikzpicture}
\caption{Impacts by category relative to baseline building with conventional building envelope}
\label{relative}
\end{figure}
答案1
尝试stack negative=on previous
用替换stack negative=separate
。
但请注意,其中一个负值非常接近于零。您将无法在图表中看到它。