我正在尝试使用 PSTricks 绘制图表。我使用的是 Miktex+Texmaker,配置为 LeTeX+dvips+ps2pdf+View PDF。有以下 latex 命令/代码:
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
%\usepackage{pst-plot}
%\usepackage{pst-math}
%\usepackage{auto-pst-pdf}
\begin{document}
\begin{figure}[h]
\centering
\scalebox{1.1}{
\psset{unit=2.5cm} % Adjust the unit size as needed
\begin{pspicture}(-3,-3)(3,3)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
\psplot{0}{5}{sqrt(x)}
\psplot[linecolor=red]{-5}{5}{ATAN(x)}
\end{pspicture}
}
\caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}
当我编译时,虽然没有出现错误,但图片却没有出现。请帮我排除故障。
答案1
除非您乐意在 postscript 中编写函数,否则您可能会发现使用 pgfplots(tikz pased)比 pstricks 更容易。x sqrt
例如,arctan 可能如下所示(请参阅注释以获取有关 atan 的帮助),尽管这不是我预期的形式。
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
%\usepackage{pst-plot}
%\usepackage{pst-math}
%\usepackage{auto-pst-pdf}
\begin{document}
\begin{figure}[h]
\centering
\scalebox{1.1}{
\psset{unit=2.5cm} % Adjust the unit size as needed
\begin{pspicture}(-3,-3)(3,3)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
\psplot{0}{5}{x sqrt}
\psplot[linecolor=red]{0}{5}{x 1 atan 3.14159 mul 180 div}
\psplot[linecolor=red]{-5}{0}{x -1 atan 3.14159 mul -180 div 3.14159 add}
\end{pspicture}
}
\caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}
答案2
选项algebraic
可用于编写正则表达式。 选项plotpoint
可用于提高精度。
ATAN
是以弧度表示的函数名称
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}
\begin{figure}[ht]
\centering
\scalebox{1.1}{
\psset{unit=2.5cm} % Adjust the unit size as needed
\begin{pspicture}(-3,-3)(3,3)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes[showorigin=false]{->}(0,0)(-3,-3)(3,3) %showorigin=false to not dispaly "0" on axes
\psplot[algebraic,plotpoints=200]{0}{3}{sqrt(x)} %algebraic for classical expression and plotpoints=200 for more précisions
\psplot[algebraic,plotpoints=200]{-3}{3}{ATAN(x)}
\end{pspicture}
}
\caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}
供参考,它也适用于 lualatex
答案3
pst-algparser.pro
atg
定义以弧度为单位输出角度的函数。它还定义AlgParser
允许代数(中缀)符号作为输入。输入是一个字符串,,(...<infix input>...)
输出是一个包含 PostScript 命令的数组,需要将其设为可执行(cvx
)并最终执行exec
:
\psplot[linecolor=red]{-5}{5}{(atg(x)) AlgParser cvx exec}
PostScript 内置函数atan
很难使用(参见 David 的回答),因为它需要两个参数作为输入,一个由切线值本身和除数组成的分数,它返回一个角度度.分数输入允许无穷大作为输入:
1 0 atan => 90
atan
使用PostScript中缀符号,以下绘图命令将生成预期的图形:
\psplot[linecolor=red]{-5}{5}{(DegtoRad(-atan(x,-1))+Pi) AlgParser cvx exec}
和atg
:
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
%\usepackage{pst-plot}
%\usepackage{pst-math}
%\usepackage{auto-pst-pdf}
\begin{document}
\begin{figure}[h]
\centering
\scalebox{1.1}{
\psset{unit=2.5cm} % Adjust the unit size as needed
\begin{pspicture}(-3,-3)(3,3)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
\psplot{0}{5}{(sqrt(x)) AlgParser cvx exec}
\psplot[linecolor=red]{-5}{5}{(atg(x)) AlgParser cvx exec}
\end{pspicture}
}
\caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}
答案4
运行lualatex
:
\DocumentMetadata{}
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}
\begin{figure}[!htb]
\centering
\psset{unit=1.5cm} % Adjust the unit size as needed
\begin{pspicture}(-3,-3)(3,3)
\psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
\psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
\psplot[algebraic,linewidth=1.5pt]{0}{3}{sqrt(x)}
\psplot[algebraic,linecolor=red,linewidth=1.5pt]{-3}{3}{ATAN(x)}
\end{pspicture}
\caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}