LaTeX forum ⇒ Graphics, Figures & Tablespst-plot | Data missing from plot Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Data missing from plot

Postby svend_tveskaeg » Tue Dec 04, 2012 8:59 am

Hi all.

Consider the following MWE:

\documentclass[danish]{article}
\usepackage{babel}
\usepackage{pst-plot}

\savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
{1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
{1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
{1992,1810},{1994,1750},{1998,2176},{2002,2399}]

\begin{document}

\begin{pspicture}(10cm,6cm)
\psset{
  xAxisLabel={},
  yAxisLabel={}
}
\begin{psgraph}[
  xAxis=false,
  yAxis=false
](0,0)(0,0)(9.5,5.5){10cm}{6cm}
\psaxes[
  Ox=1920,
  dx=1,
  Dx=10,
  Oy=0,
  dy=1,
  Dy=500
]{->}(0,0)(9.5,5.5)[{\AA}r,0][Antal deltagere,90]
\dataplot{\data}
\end{psgraph}
\end{pspicture}

\end{document}

Why is the data not plotted?

It is obviously some trivial mistake by me but I cannot find it.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

pst-plot | Data missing from plot

Postby CrazyHorse » Tue Dec 04, 2012 11:21 pm

svend_tveskaeg wrote:
Why is the data not plotted?

It is obviously some trivial mistake by me but I cannot find it.

The psgraph environment does it all for you!

\documentclass[danish]{article}
\usepackage{babel}
\usepackage{pst-plot}

\savedata\data[
  {1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
  {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
  {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
  {1992,1810},{1994,1750},{1998,2176},{2002,2399}
]

\begin{document}
  \psset{xAxisLabel={{\AA}r},yAxisLabel={Antal deltagere}}
  \begin{psgraph}[Dx=10,Dy=500,Ox=1920]{->}(1920,0)(2015,2750){10cm}{6cm} 
    \dataplot[linewidth=1.5pt,linecolor=red,showpoints]{\data}
  \end{psgraph}
\end{document}
Attachments
xxx.png
xxx.png (7.89 KiB) Viewed 5583 times

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Data missing from plot

Postby svend_tveskaeg » Wed Dec 05, 2012 4:24 am

Perfect!

Update
When I try to add a plot (using \psplot) on top of the data points, the graph is not addad;

\documentclass[danish]{article}
\usepackage{babel}
\usepackage{pst-plot}

\begin{document}

\begin{figure}
\savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
{1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
{1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
{1992,1810},{1994,1750},{1998,2176},{2002,2399}]
 \centering
  \psset{algebraic,xAxisLabel={{\AA}r},yAxisLabel={Antal deltagere}}
  \begin{pspicture}(13.5cm,8.1cm)
   \begin{psgraph}[Ox=1920,Dx=10,Dy=500]{->}(1920,0)(2015,2750){13.5cm}{8.1cm}
    \dataplot[plotstyle=dots,dotstyle=o,fillcolor=red]{\data}
   \end{psgraph}
   \psplot[linecolor=blue]{4}{52}{15.6394*x+365.858} % Linear fit of the number of competitors from 1924 to 1976. (Add other fits later.)
  \end{pspicture}
\end{figure}

\end{document}


Update 2
I have attached a screenshot from Mathematica where the fitting is performed.
Attachments
linear-fit.png
Linear fit of data.
linear-fit.png (37.98 KiB) Viewed 5571 times
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

pst-plot | Data missing from plot  Topic is solved

Postby CrazyHorse » Wed Dec 05, 2012 11:05 pm

svend_tveskaeg wrote:
Update 2
I have attached a screenshot from Mathematica where the fitting is performed.

While (true) {
  the psgraph environment is enough!
}


how should the graph be plotted? Your x-axes starts at 1920 but your plot a 4??

    \documentclass[danish]{article}
    \usepackage{babel}
    \usepackage{pst-plot}

    \begin{document}

    \savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
    {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
    {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
    {1992,1810},{1994,1750},{1998,2176},{2002,2399}]
     \centering
      \psset{algebraic,xAxisLabel={{\AA}r},yAxisLabel={Antal deltagere}}

       \begin{psgraph}[Ox=1920,Dx=10,Dy=500]{->}(1920,0)(2015,2750){13.5cm}{8.1cm}
        \dataplot[plotstyle=dots,dotstyle=o,fillcolor=red]{\data}
       \psplot[linecolor=blue]{1924}{1972}{15.6394*(x-1920)+365.858} % Linear fit of the number of competitors from 1924 to 1976. (Add other fits later.)
       \end{psgraph}

    \end{document}


by the way, PSTricks can also plot a linear

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Data missing from plot

Postby svend_tveskaeg » Thu Dec 06, 2012 6:52 am

CrazyHorse wrote:Your x-axes starts at 1920 but your plot a 4??

:oops: That is just embarrassing.

CrazyHorse wrote:by the way, PSTricks can also plot a linear

I know. I will stick to manually plotting the fit, though, since I need other fits too.

Thanks a bunch!

P.S. I ended up with the following figure:

\documentclass[danish]{article}
\usepackage{babel}
\usepackage{auto-pst-pdf,pst-plot}

\begin{document}

\begin{figure}
\savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
{1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
{1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
{1992,1810},{1994,1750},{1998,2176},{2002,2399}]
 \centering
  \psset{algebraic,xAxisLabel={\AA r},yAxisLabel={Antal deltagere}}
  \begin{pspicture}(10cm,6cm)
   \begin{psgraph}[Ox=1920,Dx=10,Dy=500]{->}(1920,0)(2015,2750){10cm}{6cm}
    \dataplot[plotstyle=dots,dotstyle=o,fillcolor=red]{\data}
    \psplot[linecolor=blue]{1924}{1976}{15.6394*(x-1920)+303.3}
    \psplot[linecolor=blue]{1980}{2002}{60.793*(x-1920)-2619.99}
   \end{psgraph}
  \end{pspicture}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 9 guests