我正在尝试制作一个龙卷风图,显示当我更改不同的值时价格会变成什么样子,我希望 x 轴像下面的图片一样,以 77 作为我的基本成本,但我不知道如何让左侧的条形图从 77 变为较小的成本,我尝试使用x dir=reverse
,但随后轴和条形图都反转了。有人能告诉我如何在不反转轴的情况下反转条形图吗?
\begin{figure}[!ht]
\pgfplotstableread[col sep=comma, header=true]{
unit,min,max
PE,77,86
Labour,77,82
ME,74,80
SI,75,79
ED,77,78
El,76,78
Land,76,78
}\loadedtable
\begin{center}
\resizebox{16cm}{!}{%
\begin{tikzpicture}
\begin{axis}[
name=popaxis,
scale only axis,
xbar,
xmin=77,
xmax=87,
width=10cm, height=8cm,
y dir = reverse,
nodes near coords = {\pgfmathprintnumber\pgfplotspointmeta},
every node near coord/.append style={/pgf/number format/fixed,
font=\small,
color=black},
xticklabel= {\pgfmathprintnumber\tick},
y tick label style={text width=3cm,align=center},
axis x line=left,
axis y line=none,
enlarge x limits = {value=0,upper},
axis line style={-},
clip=false
]
\addplot[gray,fill=lightgray!50] table[y expr =\coordindex, x expr={\thisrow{max}}] \loadedtable;
\pgfplotstablegetrowsof{\loadedtable}
\pgfmathsetmacro{\lastrow}{\pgfplotsretval-1}
\end{axis}
\begin{axis}[
at={(popaxis.north west)},anchor=north east, xshift=0cm,
scale only axis,
xbar,
y dir=reverse,
%x dir=reverse,
xmin=67,
xmax=77,
width=10cm,
height=8cm,
nodes near coords = {\pgfmathprintnumber\pgfplotspointmeta},
every node near coord/.append style={/pgf/number format/fixed, rotate = 0, anchor = east, font=\footnotesize,
color=black},
xticklabel= {\pgfmathprintnumber\tick},
axis x line=left,
axis y line*=right,
ytick = data,
yticklabels from table = {\loadedtable}{unit},
ytick align=center,
ytick pos=left,
enlarge x limits = {value=0,upper},
axis line style={-}
]
\addplot[gray,fill=lightgray!50] table[y expr =\coordindex, x expr={\thisrow{min}}] \loadedtable;
\end{axis}
\draw (0,0) -- (0,8);
\end{tikzpicture}
}
\end{center}
\end{figure}