Latex 文档中的图形

Latex 文档中的图形

enter image description here我想在我的文档中有一个函数。当 0<=x<2.5 时,它应为 f(x)=0;当 2.5<=x<5 时,它应为 g(x)=1;我可能会添加另一个 h(x)=2。我尝试使用 \addplot 命令绘制它,但我不喜欢二次坐标系的外观。是否有任何外部程序可以创建某些东西并将其放入 texmaker?

编辑:我在这里尝试过:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=10, ymin=0, ymax=4]
\addplot[thick] {{0}};
\addplot[thick] {{1}};
\end{axis} 
\end{tikzpicture} 
\end{figure}
\end{document}

首先,图形位于我之前放置的文本上方,我不知道为什么。然后我不希望它如此二次,并且不封闭上方和右侧。我甚至不知道如何真正在其中放置条件,因此函数 g(x) 从 f(x) 结束的地方开始,依此类推。我不知道这一切是否可能在那里实现 :/。谢谢

答案1

像这样(不是很清楚,你喜欢如何呈现你的功能)?

enter image description here \documentclass[10pt,a4paper]{文章} \usepackage{pgfplots} \pgfplotsset{compat=1.16}

\begin{document}
    \begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[axis lines=middle,
             xmin=0, xmax=10,
             ymin=0, ymax=4,
             no marks]
\addplot [very thick, blue, domain=0:2.5]  {0};
\addplot [very thick, blue, domain=2.5:6]  {1};
\addplot [very thick, blue, domain=6:6.5]  {2};
\addplot [very thick, blue, domain=6.5:10] {3};
\end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}

相关内容