在该网站成员提供的代码的帮助下,我能够使用 Tikzi 绘制带有 x 轴和 y 轴的图。 Tikz 绘制 Y 轴值
代码如下:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% draw x , y lines
\draw[thick,->] (0,0) -- (5.9,0) node[below left] {x axis};
\draw[thick,->] (0,0) -- (0,5.9) node[below left] {y axis};
% draw x ,y points (Values)
\foreach \i [count=\j from 0] in {0.2, 0.4, 0.6, 0.8, 1}
{
\draw (\j,2pt) -- ++ (0,-4pt) node[below] {$\j$};
\draw (2pt,\j+1) -- ++ (-4pt,0) node[left] {$\i$};
}
\end{tikzpicture}
\end{document}
现在,如何像在任何图中一样在轴的中心添加 X 标签和 y 标签(垂直)。
答案1
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
With pure \verb+tikz+:
\bigskip
\begin{tikzpicture}
% draw x , y lines
\draw[thick,->] (0,0) -- node[below=3ex] {$x$ axis} (5.9,0) ;
\draw[thick,->] (0,0) -- node[left=3em,rotate=90] {$y$ axis} (0,5.9) ;
% draw x ,y points (Values)
\foreach \i [count=\j from 0] in {0.2, 0.4, 0.6, 0.8, 1}
{
\draw (\j,2pt) -- ++ (0,-4pt) node[below] {$\j$};
\draw (2pt,\j+1) -- ++ (-4pt,0) node[left] {$\i$};
}
\end{tikzpicture}
With \verb+pgfplots+:
\bigskip
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmin=0,xmax=4.5,
ymin=0,ymax=1.05,
xlabel={$x$ axis},
x label style={at={(0.55,-0.1)}, anchor=north},
ylabel={$y$ axis},
y label style={at={(-0.2,0.5)},rotate=90},
extra x ticks={0}
]
\end{axis}
\end{tikzpicture}
\end{document}