我有以下代码:
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{bm}
\usepackage{tikz}
\usepackage{graphicx}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-}, every non boxed y axis/.append style={y axis line style=-}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=top,
axis y line=middle,
xmin=0, xmax=1.0,
ymin=0, ymax=1.0,
xtick={0, 0.2, 0.4, 0.6, 0.8, 1.0},
ytick={0, 0.2, 0.4, 0.6, 0.8, 1.0},
]
\end{axis}
\end{tikzpicture}
\end{document}
ytick 1.0 未出现(或其标签)。我该如何修复此问题?
答案1
将以下内容添加到您的序言中:
\pgfplotsset{axis y line*/center/.code={%
\def\pgfplots@yaxislinesnum{1}%
\def\pgfplots@ytickposnum{2}%
\let\pgfplots@yticklabel@pos\pgfutil@empty
}}
完整代码:
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{bm}
\usepackage{tikz}
\usepackage{graphicx}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-}, every non boxed y axis/.append style={y axis line style=-}}
\makeatletter
\pgfplotsset{
axis y line*/center/.code={\def\pgfplots@yaxislinesnum{1}\def\pgfplots@ytickposnum{2}\let\pgfplots@yticklabel@pos\pgfutil@empty},
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=top,
axis y line=middle,
xmin=0, xmax=1.0,
ymin=0, ymax=1.0,
xtick={0, 0.2, 0.4, 0.6, 0.8, 1.0},
ytick={0, 0.2, 0.4, 0.6, 0.8, 1.0},
]
\end{axis}
\end{tikzpicture}
\end{document}
答案2
axis y line=left
代替axis y line=middle
?
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
\usepackage{pgfplots} % loads tikz, which loads graphicx
\usepackage{bm}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-}, every non boxed y axis/.append style={y axis line style=-}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=top,
axis y line=left,
xmin=0, xmax=1.0,
ymin=0, ymax=1.0,
xtick={0, 0.2, 0.4, 0.6, 0.8, 1.0},
ytick={0, 0.2, 0.4, 0.6, 0.8, 1.0},
]
\end{axis}
\end{tikzpicture}
\end{document}
答案3
如果您注释掉axis y line=middle
它,它就会起作用。如果需要axis y line=middle
,请尝试在 y 范围中添加一个微小的额外位。设置ymax=1.0000001
将起作用。