下面的代码出现2个错误。
- 包 PGF 数学错误:未知函数“Criadas”(在“Criadas”中)。
- 程序包 PGF 数学错误:抱歉,浮点单元的内部例程收到格式错误的浮点数“0”。不可读部分接近“0”。
\begin{figure}
\centering
\caption{Total de Ideias Legislativas}
\label{fig:ideia-total}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
ybar,
bar width=1.2cm,
enlarge x limits=0.1,
major x tick style = transparent,
symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
xtick=data,
ymajorgrids = true,
ylabel={Ideias Legislativas},
scaled y ticks=false,
ymin=0,
ymax=100
]
\addplot [gray, fill]
coordinates {
(Criadas,100)
(Debatidas,78)
(Projetos de Lei,25)
(Leis,1)
};
\draw [->, thick, white, xshift=-.2cm] (Criadas,90) -- (Criadas,100)
node [pos=0, rotate=90, anchor=east] {\(73.003\)};
\end{axis}
\end{tikzpicture}
\end{figure}
答案1
\draw
欢迎!如果您在路径中提供坐标axis cs:
,它就可以工作。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}
\centering
\caption{Total de Ideias Legislativas.}
\label{fig:ideia-total}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
ybar,
bar width=1.2cm,
enlarge x limits=0.1,
major x tick style = transparent,
symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
xtick=data,
ymajorgrids = true,
ylabel={Ideias Legislativas},
scaled y ticks=false,
ymin=0,
ymax=100
]
\addplot[gray, fill]
coordinates {
(Criadas,100)
(Debatidas,78)
(Projetos de Lei,25)
(Leis,1)
};
\draw [->, thick, white, xshift=-.2cm]
(axis cs:Criadas,90) -- (axis cs:Criadas,100)
node [pos=0, rotate=90, anchor=east] {\(73.003\)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
您也可以使用normalized
键并使用数字坐标。此键也接受分数坐标。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{figure}
\centering
\caption{Total de Ideias Legislativas.}
\label{fig:ideia-total}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
ybar,
bar width=1.2cm,
enlarge x limits=0.1,
major x tick style = transparent,
symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
xtick=data,
ymajorgrids = true,
ylabel={Ideias Legislativas},
scaled y ticks=false,
ymin=0,
ymax=100
]
\addplot[gray, fill]
coordinates {
(Criadas,100)
(Debatidas,78)
(Projetos de Lei,25)
(Leis,1)
};
\draw [->, thick,white]
(axis cs:{[normalized]0},90) -- (axis cs:{[normalized]0},100)
node [pos=0, rotate=90, anchor=east] {\(73.003\)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
请注意,我随机添加了版本 1.16 或 1.17,根据您使用的安装,您可能需要更改\pgfplotsset{compat=1.17}
为\pgfplotsset{compat=newest}
。
答案2
不需要该\draw
命令。您还可以添加pin
(带有所需选项)来实现您想要的效果...
% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
ybar,
bar width=1.2cm,
enlarge x limits=0.1,
major x tick style = transparent,
symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
xtick=data,
ymajorgrids = true,
ylabel={Ideias Legislativas},
scaled y ticks=false,
ymin=0,
ymax=100,
]
\addplot [gray, fill] coordinates {
(Criadas,100)
(Debatidas,78)
(Projetos de Lei,25)
(Leis,1)
}
node [
at start,
coordinate,
pin={
[%
pin edge={
white,
thick,
<-,
},
white,
rotate=90,
]
left:{\pgfmathprintnumber{73003}}
},
] {}
;
\end{axis}
\end{tikzpicture}
\end{document}