我想使用 pgfplots 和 TikZ 包添加一个函数的草图,但结果并不如我所愿。我附上了所使用的代码、输出结果以及我的意图。有人能指出我应该更改什么吗?提前谢谢!
代码:
\documentclass{article}
\usepackage{pgfplots, tikz}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $x$,
ylabel = $y$,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed
]
\addplot [
domain=0:28,
samples=100,
color=red,
]
{95*x-153*x^0.83-38};
\addlegendentry{$P(x)=95x-153x^{0.83}-38$}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您的(主要)问题已由@Roland 评论解决,因此这里有一些关于绘制图表的题外话建议:
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xlabel = $x$,
ylabel = $y$,
xlabel style={anchor=north east, inner xsep=0pt},
ylabel style={anchor=north east, inner ysep=0pt},
grid,
minor tick num=4,
grid style={very thin,dashed},
xmin=-0.5,
enlarge y limits=0.1,
legend style = {font=\footnotesize},
]
\addplot [
domain=0:27,
samples=200,
color=red,
thick
]
{95*x-153*x^0.83-38};
\legend{$P(x)=95x-153x^{0.83}-38$}
\end{axis}
\end{tikzpicture}
\end{document}