PSTricks 图表存在问题

PSTricks 图表存在问题

我收到错误:

    ! Undefined control sequence.<recently read> \c@lor@to@ps }

尝试以下图表时

\documentclass[11pt]{article}
\usepackage[usenames,dvipsnames]{pstricks}
\usepackage{epsfig}
\usepackage{pst-grad} % For gradients
\usepackage{pst-plot} % For axes
\usepackage{mathtext}

\begin{document}

\psscalebox{1.0 1.0} % Change this value to rescale the drawing.
{
\begin{pspicture}(0,-2.4101124)(5.36,2.4101124)
\psline[linecolor=black, linewidth=0.04, arrowsize=0.05291666666666667cm     2.0,arrowlength=1.4,arrowinset=0.0]{->}(0.8,-2.3398876)(0.8,2.4601123)
\psline[linecolor=black, linewidth=0.04, arrowsize=0.05291666666666667cm                 2.0,arrowlength=1.4,arrowinset=0.0]{->}(0.4,-1.9398876)(5.2,-1.9398876)
\psline[linecolor=red, linewidth=0.04](1.2,-1.5398877)(4.8,2.0601122)(4.8,2.0601122)
\rput[bl](0.0,2.0601122){\textcolor{red}{f(x)}}
\rput[bl](5.2,-2.3398876){\textcolor{red}{x}}
\end{pspicture}
}

\end{document}

这应该很容易,但我不是专业人士。请帮帮我!

答案1

% compile it with
% pdflatex -shell-escape filename

\documentclass[border=12pt,12pt]{standalone}% change it back to article or whatever you want to use
\usepackage{filecontents}
\begin{filecontents*}{diagram.tex}
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-4,-1)(4.5,8.5)
    \psaxes(0,0)(-4,-1)(4,8)[$x$,0][$y$,90]
    \psplot[algebraic]{-2.5}{2.5}{x^2}
\end{pspicture}
\end{document}
\end{filecontents*}

\usepackage{pgffor,graphicx}
\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf/ps}{\immediate\write18{\compiler\space diagram.\ext}}

\begin{document}
\includegraphics{diagram.pdf}
\end{document}

在此处输入图片描述

答案2

当使用PSTricks时,您必须使用latexxelatex来编译图像。

如果您使用 TikZ/PGFPlots,您也可以使用pdflatex

\documentclass[11pt]{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    xmin=0, xmax=10,
    ymin=0, ymax=10,
    enlargelimits,
    xtick=\empty, ytick=\empty,
    axis equal image,
    xlabel=$x$, ylabel=$f(x)$
]
\addplot [red, very thick, domain=1:10] {x};
\end{axis}
\end{tikzpicture}
\end{document}

相关内容