Graphics, Figures & Tablespst-plot | Data missing from plot

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

pst-plot | Data missing from plot

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\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 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

pst-plot | Data missing from plot

Post by CrazyHorse »

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!

Code: Select all

\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 6322 times
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Data missing from plot

Post by svend_tveskaeg »

Perfect!

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

Code: Select all

\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 of data.
Linear fit of data.
linear-fit.png (37.98 KiB) Viewed 6310 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

Post by CrazyHorse »

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

Code: Select all

While (true) {
  the psgraph environment is enough!
}
how should the graph be plotted? Your x-axes starts at 1920 but your plot a 4??

Code: Select all

    \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

Post by svend_tveskaeg »

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:

Code: Select all

\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)
Post Reply