使用以下代码:
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=40,ymin=0, ymax=42, xlabel=Φρούτα,ylabel=Γάλα]
\addplot [color=Blue] coordinates {
(0 ,40)
(20, 30)
(30, 20)
(35, 10)
(39, 0)
};
\end{axis}
\end{tikzpicture}
我得到以下结果
但是,我怎样才能实现以下目标呢?
答案1
使用axis lines = middle
(参见 pgfplots 手册当前版本 [1.8] 的第 4.8.9 节)。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0,
xmax = 40,
ymin = 0,
ymax = 42,
axis lines = middle,
enlargelimits = true,
]
\addplot+[mark = none] coordinates {%
(0 ,40)
(20, 30)
(30, 20)
(35, 10)
(39, 0)};
\node[below left] at (axis cs:0,0) {$0$};
\end{axis}
\end{tikzpicture}
\end{document}
更新我更改了轴的样式(感谢@Jake),以便它们更好地贴合您的示例(axis lines = left
)。我还用xlabel
和ylabel
键添加了轴标签。当您输入一些希腊字母时,我使用包xits
并用编译了整个文档。最后,我使用坐标系lualatex
在点上方添加了某种标签。请注意,环境范围内定义的任何节点都可以在环境范围之外访问。(0,40)
axis cs
axis
\documentclass{standalone}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0,
xmax = 40,
ymin = 0,
ymax = 42,
axis lines = left,
xlabel = Φρούτα,
ylabel = Γάλα
]
\addplot+[mark = none] coordinates {%
(0,40)
(20,30)
(30,20)
(35,10)
(39,0)};
\coordinate (A) at (axis cs:0,40);
\end{axis}
\node[above right] at (A) {$A$};
\end{tikzpicture}
\end{document}