例如,此代码有效:
\documentclass{minimal}
\usepackage{pstricks}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes(0,0)(-5,-5)(5,5)
\psplot[algebraic,xunit=0.5cm,linewidth=1pt]{-5}{5}{x*cos(x)}
\end{pspicture}
\end{document}
但是输入atan(x)
,sqrt(x)
(我猜这个列表并不完整)而x*cos(x)
不是 ,则什么也没有发生。
答案1
这pst-math
包提供了ATAN
反正切函数的函数。该sqrt
函数有域[0,\infty)
,这就是您的代码不起作用的原因(您为其提供了域[-5,5]
)
\documentclass{article}
\usepackage{pst-plot}
\usepackage{pst-math}
\begin{document}
\psset{algebraic,unit=0.5cm,linewidth=1pt}
\begin{pspicture}(-5,-5)(5,5)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes(0,0)(-5,-5)(5,5)
\psplot{0}{5}{sqrt(x)}
\psplot[linecolor=red]{-5}{5}{ATAN(x)}
\end{pspicture}
\end{document}
答案2
也可以将根函数绘制为参数图,这样就不必考虑负值:
\documentclass{article}
\usepackage{pst-plot}
\usepackage{pst-math}
\begin{document}
\begin{pspicture}(-5,-3)(5,3)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!40]
\psaxes[axesstyle=frame,Dx=2,Dy=2](0,0)(-5,-3)(5,3)
\psset{algebraic,linewidth=1.5pt}
\psparametricplot{-2.2}{2.2}{t^2 | t}
\psplot[linecolor=red]{-5}{5}{ATAN(x)}
\end{pspicture}
\end{document}
答案3
\documentclass[pstricks,border=0pt,12pt,dvipsnames]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot}
\usepackage{pst-math}
\usepackage[nomessages]{fp}
\FPeval\XMin{0-5}
\FPeval\XMax{5}
\FPeval\YMin{0-pi}
\FPeval\YMax{pi}
\FPeval\XOL{0-1/3} % of DeltaX
\FPeval\XOR{1/3} % of DeltaX
\FPeval\YOB{0-1/3} % of DeltaY
\FPeval\YOT{1/3} % of DeltaY
\FPset\TrigLabelBase{4}
\FPeval\DeltaX{1}
\FPeval\DeltaY{pi/TrigLabelBase}
\FPeval\AxisL{XMin+DeltaX*XOL}
\FPeval\AxisR{XMax+DeltaX*XOR}
\FPeval\AxisB{YMin+DeltaY*YOB}
\FPeval\AxisT{YMax+DeltaY*YOT}
\newlength\Width\Width=12cm
\newlength\Height\Height=8cm
\newlength\llx\llx=-5pt
\newlength\urx\urx=15pt
\newlength\lly\lly=-5pt
\newlength\ury\ury=15pt
\psset
{
llx=\llx,
lly=\lly,
urx=\urx,
ury=\ury,
xtrigLabels=false,
ytrigLabels=true,
trigLabelBase=\TrigLabelBase,
labelFontSize=\scriptstyle,
xAxisLabel=$x$,
yAxisLabel=$y$,
algebraic,
plotpoints=500,
}
\def\f{ATAN(x)}
\def\g{sqrt(x)}
\begin{document}
\pslegend[lt]{%
\color{NavyBlue}\rule{12pt}{1pt} & \color{NavyBlue} $y=\tan^{-1} x$\\
\color{Red}\rule{12pt}{1pt} & \color{Red} $y=\sqrt x$
}
\begin{psgraph}
[
dx=\DeltaX,
dy=\DeltaY,
linecolor=lightgray,
tickcolor=gray,
ticksize=-3pt 3pt,
axespos=top,
]{<->}(0,0)(\AxisL,\AxisB)(\AxisR,\AxisT){\dimexpr\Width-\urx+\llx}{!}%{\dimexpr\Height-\ury+\lly}
\psaxes
[
dx=\DeltaX,
dy=\DeltaY,
labels=none,
subticks=5,
tickwidth=.4pt,
subtickwidth=.2pt,
tickcolor=Orange!20,
subtickcolor=ForestGreen!20,
xticksize=\YMin\space \YMax,
yticksize=\XMin\space \XMax,
subticksize=1,
](0,0)(\XMin,\YMin)(\XMax,\YMax)
\psplot[linecolor=NavyBlue]{-5}{5}{\f}
\psplot[linecolor=Red]{0}{5}{\g}
\end{psgraph}
\end{document}
文档
需要加载pst-math
因为pst-plot
仅定义了以下函数。
sin
,,,,以弧度为cos
单位tan
acos
asin
log
,ln
ceiling
,,,,floor
truncate
round
sqrt
(平方根)abs
(绝对值)fact
(阶乘)Sum
IfTE
(格结构)
答案4
因为我们总是鼓励做不同的事情,这是一个使用pgfplots
。注意,这个包degrees
默认使用,所以我们需要转换为radians
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-5,xmax=5,
ymin=-5,ymax=5,
grid=both]
\addplot[red]expression[domain=0:5]{sqrt(x)};
\addplot[blue]expression[domain=-5:5]{rad(atan(x))};
\end{axis}
\end{tikzpicture}
\end{document}