是否可以选择(垂直线)的基线ycomb
?
例如,在对数刻度中,默认基线位于y=1
(或y=10^0
)。但我想将其设为y=0
(即负无穷大)。原因是如果所有值都低于,则y=1
梳子会向上而不是向下 (这令人困惑)。
梅威瑟:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymode=log]
\addplot[ycomb,mark=*] coordinates {% #points 5
( 0, 100 )
( 1, 10 )
( 2, 1 )
( 3, 0.1 )
( 4, 0.01 )
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以设置log origin=infty
让ycomb
情节从情节底部开始:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymode=log, log origin=infty]
\addplot[ycomb,mark=*] coordinates {% #points 5
( 0, 100 )
( 1, 10 )
( 2, 1 )
( 3, 0.1 )
( 4, 0.01 )
};
\end{axis}
\end{tikzpicture}
\end{document}
如果要使梳状图或条形图从轴的顶部开始,则必须重新定义内部宏。将以下代码块放入序言中将使该选项log origin=-infty
可用,从而使图从顶部开始:
\makeatletter
\pgfplotsset{
/pgfplots/log origin x/-infty/.code={\def\pgfplots@log@origin@choice@x{2}},
/pgfplots/log origin y/-infty/.code={\def\pgfplots@log@origin@choice@y{2}},
/pgfplots/log origin z/-infty/.code={\def\pgfplots@log@origin@choice@z{2}}
}
\def\pgfplots@prepare@ZERO@coordinates{%
\ifpgfplots@xislinear
\ifpgfplots@apply@datatrafo@x
\pgfplotscoordmath{x}{parsenumber}{0}%
\pgfplotscoordmath{x}{datascaletrafo}{\pgfmathresult}%
\global\let\pgfplots@logical@ZERO@x=\pgfmathresult
\else
\gdef\pgfplots@logical@ZERO@x{0}%
\fi
% this works in standard fixed pt math:
\pgfplotsmathmax{\pgfplots@logical@ZERO@x}{\pgfplots@xmin}%
\global\let\pgfplots@logical@ZERO@x=\pgfmathresult
\pgfplotsmathmin{\pgfplots@logical@ZERO@x}{\pgfplots@xmax}%
\global\let\pgfplots@logical@ZERO@x=\pgfmathresult
\else
\if\pgfplots@log@origin@choice@x0%
\global\let\pgfplots@logical@ZERO@x=\pgfplots@xmin%
\else
\if\pgfplots@log@origin@choice@x2%
\global\let\pgfplots@logical@ZERO@x=\pgfplots@xmax%
\else
\gdef\pgfplots@logical@ZERO@x{0}%
\fi
\fi
\fi
%
\ifpgfplots@yislinear
\ifpgfplots@apply@datatrafo@y
\pgfplotscoordmath{y}{parsenumber}{0}%
\pgfplotscoordmath{y}{datascaletrafo}{\pgfmathresult}%
\global\let\pgfplots@logical@ZERO@y=\pgfmathresult
\else
\gdef\pgfplots@logical@ZERO@y{0}%
\fi
\pgfplotsmathmax{\pgfplots@logical@ZERO@y}{\pgfplots@ymin}%
\global\let\pgfplots@logical@ZERO@y=\pgfmathresult
\pgfplotsmathmin{\pgfplots@logical@ZERO@y}{\pgfplots@ymax}%
\global\let\pgfplots@logical@ZERO@y=\pgfmathresult
\else
\if\pgfplots@log@origin@choice@y0%
\global\let\pgfplots@logical@ZERO@y=\pgfplots@ymin%
\else
\if\pgfplots@log@origin@choice@y2%
\global\let\pgfplots@logical@ZERO@y=\pgfplots@ymax%
\else
\gdef\pgfplots@logical@ZERO@y{0}%
\fi
\fi
\fi
%
\ifpgfplots@threedim
\ifpgfplots@zislinear
\ifpgfplots@apply@datatrafo@z
\pgfplotscoordmath{z}{parsenumber}{0}%
\pgfplotscoordmath{z}{datascaletrafo}{\pgfmathresult}%
\global\let\pgfplots@logical@ZERO@z=\pgfmathresult
\else
\gdef\pgfplots@logical@ZERO@z{0}%
\fi
\pgfplotsmathmax{\pgfplots@logical@ZERO@z}{\pgfplots@zmin}%
\global\let\pgfplots@logical@ZERO@z=\pgfmathresult
\pgfplotsmathmin{\pgfplots@logical@ZERO@z}{\pgfplots@zmax}%
\global\let\pgfplots@logical@ZERO@z=\pgfmathresult
\else
\if\pgfplots@log@origin@choice@z0%
\global\let\pgfplots@logical@ZERO@z=\pgfplots@zmin%
\else
\if\pgfplots@log@origin@choice@z2%
\global\let\pgfplots@logical@ZERO@z=\pgfplots@zmax%
\else
\gdef\pgfplots@logical@ZERO@z{0}%
\fi
\fi
\fi
\fi
%
%
\ifpgfplots@threedim
\pgfplotsqpointxyz{\pgfplots@logical@ZERO@x}{\pgfplots@logical@ZERO@y}{\pgfplots@logical@ZERO@z}%
\else
\pgfplotsqpointxy{\pgfplots@logical@ZERO@x}{\pgfplots@logical@ZERO@y}%
\fi
\xdef\pgfplots@ZERO@x{\the\pgf@x}%
\xdef\pgfplots@ZERO@y{\the\pgf@y}%
\xdef\pgfplotspointaxisorigin{\noexpand\global\pgf@x=\pgfplots@ZERO@x\space\noexpand\global\pgf@y=\pgfplots@ZERO@y\space}%
%
%
%--------------------------------------------------
% \pgfkeyslet{/pgfplots/axis/zero/x}\pgfplots@logical@ZERO@x
% \pgfkeyslet{/pgfplots/axis/zero/y}\pgfplots@logical@ZERO@y
% \ifpgfplots@threedim
% \pgfkeyslet{/pgfplots/axis/zero/z}\pgfplots@logical@ZERO@z
% \fi
%--------------------------------------------------
}%
\makeatother