Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to draw a curve in latex but when I put this code

\psset{algebraic=true}
\pspicture(-2,-0.5)(2,2)

\psline{<->}(-2,0)(2,0)
\psline{->}(0,-0.5)(0,2)
\psplot{-1.5}{1}{x*x+x}

\endpspicture

theses errors appear

! Undefined control sequence.<recently read> \c@lor@to@ps \psline(
! Undefined control sequence.\XC@usec@lor ...string \color@ #1#2\endcsname \@@\fi \space \psline(
! Undefined control sequence.<recently read> \c@lor@to@ps \psline

Please if someone can help me because i didn't understand why this error appears.

\documentclass{article}
\usepackage[french]{babel} 
\usepackage{color} 
\usepackage{xcolor} %les couleurs 
\definecolor{myblue}{rgb}{0.2,0.4,1} 
\usepackage{layout} 
\usepackage[top=2 cm, bottom=2 cm, left=2 cm, right=2 cm]{geometry} 
\usepackage{setspace} 
\usepackage{graphicx} 
\usepackage{array} 
\usepackage{pstricks-add} 
\usepackage{pst-eucl} 

\begin{document} 
\psset{algebraic=true} 
\pspicture(-2,-0.5)(2,2) 
\psline{<->}(-2,0)(2,0) 
\psline{->}(0,-0.5)(0,2) 
\psplot{-1.5}{1}{x*x+x} 
\endpspicture 
\end{document} 
share|improve this question

4 Answers 4

The main problem with your MWE was the line

\usepackage[pdftex]{graphicx}

which, when using PSTricks will cause some problems (unless you use How to use PSTricks in pdfLaTeX?)

Note also that there's no need to load the color AND xcolor package- only load the xcolor package in the future.

I've stripped your code down to the following, which works either with xelatex or with the latex->dvips->ps2pdf routine.

enter image description here

\documentclass{article}
\usepackage[french]{babel} 
\usepackage{pstricks-add} 

\begin{document} 
\psset{algebraic=true} 
\pspicture(-2,-0.5)(2,2) 
\psline{<->}(-2,0)(2,0) 
\psline{->}(0,-0.5)(0,2) 
\psplot{-1.5}{1}{x*x+x} 
\endpspicture 
\end{document} 
share|improve this answer

When using PStricks with PDF output, you need to either

  1. Compile with latex and then run dvi2pdf.
  2. Compile with xelatex.
  3. Compile with pdflatex with \usepackage{auto-pst-pdf}.

In the first two cases, you need to remove the pdftex option from \usepackage{graphicx}, and in the third case, it is still recommended to omit the option.

Alternatively, you could

  1. Use pgfplots, which works natively with pdflatex. For example

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle, enlargelimits=true, xtick=\empty, ytick=\empty]
\addplot [domain=-1.5:1, thick] {x^2+x};
\end{axis}
\end{tikzpicture}
\end{document}

will give you

share|improve this answer
    
thank you for your answers please i have an anathor question i would like to make a curve that i input its data –  boutheina Apr 23 '12 at 13:20
    
@boutheina: You should ask a new question for that. –  Jake Apr 23 '12 at 13:21
    
@ Jake: i can't publish my question that is:good afternoon, I would like to draw a curve in latex with my own data so how i can make that please? this error appear It does not meet our quality standards. –  boutheina Apr 23 '12 at 13:59
    
@boutheina: You'll need to add more information to your question: What compiler do you use (pdflatex, latex, xelatex)? What plotting package do you want to use (PStricks, pgfplots)? In what form do you want to provide the plot data (a text file of comma separated values, coordinates you'll enter into the .tex file)? –  Jake Apr 23 '12 at 14:03
    
i change my questio to :good afternoon, I would like to draw a curve in latex with my own data so how i can make that please? i use the compiler pdflatex and i use plotting package pgfplots and I don't know what is the best form to provide this? but the same error still –  boutheina Apr 23 '12 at 14:22

Plotting a curve to which you supply your own data points using pstricks is possible using pst-plot. You can either input the data directly in your .tex file, or read it from an external file. Here's a small example, taken from the pst-plot documentation (see section 2 Plotting data records, p 5-6):

enter image description here

\documentclass{article}
\usepackage{pst-plot}% http://ctan.org/pkg/pst-plot
\usepackage{filecontents}% http://ctan.org/pkg/filecontents
\begin{document}
\begin{pspicture}(4,3)
  \psset{xunit=.2cm,yunit=1.5cm}
  \savedata{\mydata}[
    {{0, 0}, {1., 0.946083}, {2., 1.60541}, {3., 1.84865}, {4., 1.7582},
    {5., 1.54993}, {6., 1.42469}, {7., 1.4546}, {8., 1.57419},
    {9., 1.66504}, {10., 1.65835}, {11., 1.57831}, {12., 1.50497},
    {13., 1.49936}, {14., 1.55621}, {15., 1.61819}, {16., 1.6313},
    {17., 1.59014}, {18., 1.53661}, {19., 1.51863}, {20., 1.54824}}]
  \dataplot[plotstyle=curve,showpoints,dotstyle=triangle]{\mydata}
  \psline{<->}(0,2)(0,0)(22,0)
\end{pspicture}

\bigskip

\begin{filecontents*}{foo.data}
[{0, 0}, {1., 0.946083}, {2., 1.60541}, {3., 1.84865}, {4., 1.7582},
 {5., 1.54993}, {6., 1.42469}, {7., 1.4546}, {8., 1.57419},
 {9., 1.66504}, {10., 1.65835}, {11., 1.57831}, {12., 1.50497},
 {13., 1.49936}, {14., 1.55621}, {15., 1.61819}, {16., 1.6313},
 {17., 1.59014}, {18., 1.53661}, {19., 1.51863}, {20., 1.54824}]
\end{filecontents*}

\begin{pspicture}(4,3)
  \psset{xunit=.2cm,yunit=1.5cm}
  \readdata{\foo}{foo.data}
  \dataplot[plotstyle=curve,showpoints,dotstyle=diamond]{\foo}
  \psline{<->}(0,2)(0,0)(22,0)
\end{pspicture}

\end{document}​
share|improve this answer

Compile with pdflatex --shell-escape filename.tex or xelatex --shell-escape filename.tex.

%filename.tex
\documentclass{article}

\usepackage{filecontents}

\begin{filecontents*}{xxx.tex}
\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pstricks-add} 
\begin{document} 
\pspicture*[showgrid](-2,-1)(2,2) 
    \psaxes{->}(0,0)(-1.75,-0.75)(1.5,1.5)[$x$,0][$y$,90]
    \psplot[algebraic,linecolor=red]{-1.5}{1}{x^2+x} 
\endpspicture* 
\end{document} 
\end{filecontents*}


\usepackage{graphicx}

\def\fig#1#2{
    \immediate\write18{xelatex #1}%
    \begin{figure}
        \centering
        \includegraphics[width=0.5\linewidth]{#1}
        \caption{#2}
        \label{fig:#1}
    \end{figure}%
}
\begin{document}
    \fig{xxx}{This is the graph of $y=f(x)=x^2+x$}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.