pgfplot 中的双(相反方向)条形图,x 轴上有对数刻度

pgfplot 中的双(相反方向)条形图,x 轴上有对数刻度

我正在使用 制作双条形图(方向相反)pgfplots。我有非常小的数字,绘制时条形的长度非常小。我想对 x 轴进行对数缩放,为此我使用了semilogxaxis,这就是出错的地方。

以下是示例:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
name=like,
scale only axis,
xbar, xmin=0, xmax=1, %xbar=2pt,
xlabel={Percentage Relative Error$_2$},
width=5cm, height= 8cm,
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={sa,safda,afa,afa,af},
y tick label style={text width=2cm,align=center},
axis x line=left,
axis y line=none,
clip=false
]
%\addplot[green,fill=green] coordinates {
\addplot[purple, fill=purple]
coordinates {
    (0.0010015,1)
    (0.000542511,2)
    (0.00599,3)
    (0.000279,4)
    (0.05813,5)
    (0.005315, 6)
    (0.80101, 7)};
\node[xshift=-1.5cm,align=center] at (axis cs:0,7) {$a_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,6) {$b_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,5) {$c_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,4) {$a_{\tau}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,3) {$\alpha_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,2) {$\beta_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,1) {$\Gamma_{KC}$};
\end{axis}

%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{axis}[
at={(like.north west)},anchor=north east, xshift=-3cm,
scale only axis,
xbar, xmin=0,xmax=1, %title={Relative Errors},
xlabel={Percentage Relative Error$_{1/2}$},
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={},
width=5cm, height= 8cm,
x dir=reverse,
axis x line=left,
axis y line=none,
]
%\addplot[red,fill=red] coordinates {
\addplot[teal, fill=teal]
coordinates {
    (0.000601462,1)
    (0.00035377,2)
    (0.021535,3)
    (0.00003571, 4)
    (0.0012904,5)
    (0.0025222,6)
    (0.00599214,7)};
\end{axis}
\end{tikzpicture}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{tikzpicture}
\begin{semilogxaxis}[
name=like, 
scale only axis,
xbar, xmin=0, xmax=1, %xbar=2pt,
xlabel={Percentage Relative Error$_2$},
width=5cm, height= 8cm,
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={sa,safda,afa,afa,af},
y tick label style={text width=2cm,align=center},
axis x line=left,
axis y line=none,
clip=false
]
%\addplot[green,fill=green] coordinates {
\addplot[purple, fill=purple]
coordinates {
    (0.0010015,1)
    (0.000542511,2)
    (0.00599,3)
    (0.000279,4)
    (0.05813,5)
    (0.005315, 6)
    (0.80101, 7)};
\node[xshift=-1.5cm,align=center] at (axis cs:0,7) {$a_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,6) {$b_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,5) {$c_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,4) {$a_{\tau}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,3) {$\alpha_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,2) {$\beta_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,1) {$\Gamma_{KC}$};
\end{semilogxaxis}

%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{semilogxaxis}[
at={(like.north west)},anchor=north east, xshift=-3cm,
scale only axis,
xbar, xmin=0,xmax=1, %title={Relative Errors},
xlabel={Percentage Relative Error$_{1/2}$},
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={},
width=5cm, height= 8cm,
x dir=reverse,
axis x line=left,
axis y line=none,
]
%\addplot[red,fill=red] coordinates {
\addplot[teal, fill=teal]
coordinates {
    (0.000601462,1)
    (0.00035377,2)
    (0.021535,3)
    (0.00003571, 4)
    (0.0012904,5)
    (0.0025222,6)
    (0.00599214,7)};
\end{semilogxaxis}
\end{tikzpicture}

\end{document}

以下是图片:https://i.stack.imgur.com/tBbmS.jpg

我需要与第一张图相同的风格。

答案1

对于线性图,条形图从 0 开始,但对于对数图,条形图从 10^0=1 开始。可以使用 来修复此问题[log origin x=infty]。同样,[x min=0]被忽略,但(axis cs:0,7)被推到最右边。

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
name=like,
scale only axis,
xbar, xmin=0, xmax=1, %xbar=2pt,
xlabel={Percentage Relative Error$_2$},
width=5cm, height= 8cm,
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={sa,safda,afa,afa,af},
y tick label style={text width=2cm,align=center},
axis x line=left,
axis y line=none,
clip=false
]
%\addplot[green,fill=green] coordinates {
\addplot[purple, fill=purple]
coordinates {
    (0.0010015,1)
    (0.000542511,2)
    (0.00599,3)
    (0.000279,4)
    (0.05813,5)
    (0.005315, 6)
    (0.80101, 7)};
\pgfplotsextra{%
\node[xshift=-1.5cm,align=center] at (axis cs:0,7) {$a_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,6) {$b_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,5) {$c_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,4) {$a_{\tau}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,3) {$\alpha_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,2) {$\beta_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0,1) {$\Gamma_{KC}$};
}
\end{axis}

%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{axis}[
at={(like.north west)},anchor=north east, xshift=-3cm,
scale only axis,
xbar, xmin=0,xmax=1, %title={Relative Errors},
xlabel={Percentage Relative Error$_{1/2}$},
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={},
width=5cm, height= 8cm,
x dir=reverse,
axis x line=left,
axis y line=none,
]
%\addplot[red,fill=red] coordinates {
\addplot[teal, fill=teal]
coordinates {
    (0.000601462,1)
    (0.00035377,2)
    (0.021535,3)
    (0.00003571, 4)
    (0.0012904,5)
    (0.0025222,6)
    (0.00599214,7)};
\end{axis}
\end{tikzpicture}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{tikzpicture}
\begin{semilogxaxis}[
name=like, 
scale only axis,
xbar, xmax=1, xmin=.00001,
xlabel={Percentage Relative Error$_2$},
width=5cm, height= 8cm,
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={sa,safda,afa,afa,af},
y tick label style={text width=2cm,align=center},
axis x line=left,
axis y line=none,
clip=false,
log origin x=infty
]
%\addplot[green,fill=green] coordinates {
\addplot[purple, fill=purple]
coordinates {
    (0.0010015,1)
    (0.000542511,2)
    (0.00599,3)
    (0.000279,4)
    (0.05813,5)
    (0.005315, 6)
    (0.80101, 7)};
\pgfplotsextra{%
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,7) {$a_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,6) {$b_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,5) {$c_{\phi}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,4) {$a_{\tau}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,3) {$\alpha_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,2) {$\beta_{KC}$};
\node[xshift=-1.5cm,align=center] at (axis cs:0.00001,1) {$\Gamma_{KC}$};
}
\end{semilogxaxis}

%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{semilogxaxis}[
at={(like.north west)},anchor=north east, xshift=-3cm,
scale only axis,
xbar, xmax=1, xmin=0.00001,  %title={Relative Errors},
xlabel={Percentage Relative Error$_{1/2}$},
ytick={0.2, 0.4, 0.6, 0.8, 1},
yticklabels={},
width=5cm, height= 8cm,
x dir=reverse,
axis x line=left,
axis y line=none,
log origin x=infty
]
%\addplot[red,fill=red] coordinates {
\addplot[teal, fill=teal]
coordinates {
    (0.000601462,1)
    (0.00035377,2)
    (0.021535,3)
    (0.00003571, 4)
    (0.0012904,5)
    (0.0025222,6)
    (0.00599214,7)};
\end{semilogxaxis}
\end{tikzpicture}

\end{document}

演示

相关内容