Math & ScienceBad luck with plots and pstricks :(

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
turbomac
Posts: 34
Joined: Sat Oct 10, 2009 9:38 pm

Bad luck with plots and pstricks :(

Post by turbomac »

Hi everyone:

I need to plot a function within a paper I need to write. I don't want to capture a screenshot of the function. I want to do it with Pstricks, but I have had very bad luck with it. Every thing I have tried to do, fails one way or another. I don't know why.

This code was taken from the PSTRICK exapmples page (http://tug.org/PSTricks/main.cgi?file=pst-plot/examples).

Code: Select all

\listfiles
\documentclass[12pt,a4paper]{article} % Herbert Voss <voss@perce.de> 2004-06-26
\usepackage{pst-plot}
\usepackage{pstricks-add}
\usepackage{amsmath}
%
\def\pshlabel#1{\footnotesize#1}\def\psvlabel#1{\footnotesize#1}
%
\begin{document}

\psset{yunit=4cm,xunit=4}
\begin{pspicture}(-2,0)(2,1)
%  \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0]
  \psaxes[Dy=0.25]{->}(0,0)(-2,0)(2,1)
  \uput[-90](2,0){x}\uput[0](0,1){y}
  \rput[lb](1,0.75){$\sigma =0.5$}
  \rput[lb](-2,0.5){$f(x)=\dfrac{1}{\sigma\sqrt{2\pi}}\,e^{-\dfrac{x^2}{2\sigma{}^2}}$}
  \psplot[linecolor=red, linewidth=2pt]{-1.8}{1.8}{%
    /sigma 0.5 def
    /e 2.718282 def
    /C 1 sigma div 6.2831 sqrt div def
    e x dup mul 2 div sigma dup mul div neg exp C mul}
\end{pspicture}

\begin{verbatim}
\usepackage{pst-plot}
\usepackage{pstricks-add}
\usepackage{amsmath}
%
\def\pshlabel#1{\footnotesize#1}\def\psvlabel#1{\footnotesize#1}
%
\begin{document}

\psset{yunit=4cm,xunit=4}
\begin{pspicture}(-2,0)(2,1)
%  \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0]
  \psaxes[Dy=0.25]{->}(0,0)(-2,0)(2,1)
  \uput[-90](2,0){x}\uput[0](0,1){y}
  \rput[lb](1,0.75){$\sigma =0.5$}
  \rput[lb](-2,0.5){$f(x)=\dfrac{1}{\sigma\sqrt{2\pi}}\,e^{-\dfrac{x^2}{2\sigma{}^2}}$}
  \psplot[linecolor=red, linewidth=2pt]{-1.8}{1.8}{%
    /sigma 0.5 def
    /e 2.718282 def
    /C 1 sigma div 6.2831 sqrt div def
    e x dup mul 2 div sigma dup mul div neg exp C mul}
\end{pspicture}
\end{verbatim}

\end{document}
But... It doesn't work. It gives an error that says "Gaussian.tex:14:Undefined control sequence. \psaxes[Dy=0.25]{->}(0,0)(-2,0)(2,1)"

The same thing occurs with psset and other commands :(

Any suggestions??
Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Bad luck with plots and pstricks :(

Post by josephwright »

Can you post your log, and in particular the \listfiles output. I get a successful compilation with a file list

Code: Select all

 *File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size12.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
pst-plot.sty    2010/01/22 package wrapper for pst-plot.tex
pstricks.sty    2008/11/26 v0.40 LaTeX wrapper for `PSTricks' (RN,HV)
pstricks.tex    2010/04/26 v2.05 `PSTricks' (tvz,hv)
pst-xkey.tex    2005/11/25 v1.6 PSTricks specialization of xkeyval (HA)
 xkeyval.sty    2008/08/13 v2.6a package option processing (HA)
 xkeyval.tex    2008/08/13 v2.6a key=value parser (HA)
  pst-fp.tex    2010/04/26 v2.05 `PST-fp' (hv)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
   dvips.def    1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
pst-plot.tex    2010/04/29 1.15 `pst-plot' (tvz,hv)
pstricks-add.sty    2010/02/11 v. 0.14 package wrapper for pstricks-add.tex (hv
)
pstricks-add.tex    2010/03/12 v3.39 `PSTricks-add' (hv)
 amsmath.sty    2000/07/18 v2.13 AMS math features
 amstext.sty    2000/06/29 v2.01
  amsgen.sty    1999/11/30 v2.0
  amsbsy.sty    1999/11/29 v1.2d
  amsopn.sty    1999/12/14 v2.01 operator names
 ***********
Joseph Wright
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Bad luck with plots and pstricks :(

Post by CrazyHorse »

turbomac wrote: I need to plot a function within a paper I need to write. I don't want to capture a screenshot of the function. I want to do it with Pstricks, but I have had very bad luck with it. Every thing I have tried to do, fails one way or another. I don't know why.
you have to run the sequence latex->dvips->ps2pdf
See http://tug.org/PSTricks/main.cgi?file=pdf/pdfoutput

However, for the Gaussian function see also pst-func
http://mirror.ctan.org/graphics/pstrick ... nc-doc.pdf

Herbert
turbomac
Posts: 34
Joined: Sat Oct 10, 2009 9:38 pm

Bad luck with plots and pstricks :(

Post by turbomac »

CrazyHorse wrote:
turbomac wrote: I need to plot a function within a paper I need to write. I don't want to capture a screenshot of the function. I want to do it with Pstricks, but I have had very bad luck with it. Every thing I have tried to do, fails one way or another. I don't know why.
you have to run the sequence latex->dvips->ps2pdf
See http://tug.org/PSTricks/main.cgi?file=pdf/pdfoutput

However, for the Gaussian function see also pst-func
http://mirror.ctan.org/graphics/pstrick ... nc-doc.pdf

Herbert
It worked, but why doesn't pdflatex admit pstricks commands??
Thanks :)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Bad luck with plots and pstricks :(

Post by localghost »

turbomac wrote: It worked, but why doesn't pdflatex admit pstricks commands? [...]
The pstricks package injects Postscript code into the document (»PostScript Tricks«). And that's what pdflatex can't handle. But you can use the (auto-)pst-pdf package to compile directly with pdflatex. This package needs shell escape enabled. See the manual for details.


Best regards
Thorsten
Post Reply