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:

  1. \documentclass[danish]{article}
  2. \usepackage{babel}
  3. \usepackage{pst-plot}
  4.  
  5. \savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
  6. {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
  7. {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
  8. {1992,1810},{1994,1750},{1998,2176},{2002,2399}]
  9.  
  10. \begin{document}
  11.  
  12. \begin{pspicture}(10cm,6cm)
  13. \psset{
  14. xAxisLabel={},
  15. yAxisLabel={}
  16. }
  17. \begin{psgraph}[
  18. xAxis=false,
  19. yAxis=false
  20. ](0,0)(0,0)(9.5,5.5){10cm}{6cm}
  21. \psaxes[
  22. Ox=1920,
  23. dx=1,
  24. Dx=10,
  25. Oy=0,
  26. dy=1,
  27. Dy=500
  28. ]{->}(0,0)(9.5,5.5)[{\AA}r,0][Antal deltagere,90]
  29. \dataplot{\data}
  30. \end{psgraph}
  31. \end{pspicture}
  32.  
  33. \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)

Tags:

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

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!

  1. \documentclass[danish]{article}
  2. \usepackage{babel}
  3. \usepackage{pst-plot}
  4.  
  5. \savedata\data[
  6. {1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
  7. {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
  8. {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
  9. {1992,1810},{1994,1750},{1998,2176},{2002,2399}
  10. ]
  11.  
  12. \begin{document}
  13. \psset{xAxisLabel={{\AA}r},yAxisLabel={Antal deltagere}}
  14. \begin{psgraph}[Dx=10,Dy=500,Ox=1920]{->}(1920,0)(2015,2750){10cm}{6cm}
  15. \dataplot[linewidth=1.5pt,linecolor=red,showpoints]{\data}
  16. \end{psgraph}
  17. \end{document}
Attachments
xxx.png
xxx.png (7.89 KiB) Viewed 3882 times

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

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;

  1. \documentclass[danish]{article}
  2. \usepackage{babel}
  3. \usepackage{pst-plot}
  4.  
  5. \begin{document}
  6.  
  7. \begin{figure}
  8. \savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
  9. {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
  10. {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
  11. {1992,1810},{1994,1750},{1998,2176},{2002,2399}]
  12. \centering
  13. \psset{algebraic,xAxisLabel={{\AA}r},yAxisLabel={Antal deltagere}}
  14. \begin{pspicture}(13.5cm,8.1cm)
  15. \begin{psgraph}[Ox=1920,Dx=10,Dy=500]{->}(1920,0)(2015,2750){13.5cm}{8.1cm}
  16. \dataplot[plotstyle=dots,dotstyle=o,fillcolor=red]{\data}
  17. \end{psgraph}
  18. \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.)
  19. \end{pspicture}
  20. \end{figure}
  21.  
  22. \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 3870 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

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.

  1. While (true) {
  2. the psgraph environment is enough!
  3. }


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

  1. \documentclass[danish]{article}
  2. \usepackage{babel}
  3. \usepackage{pst-plot}
  4.  
  5. \begin{document}
  6.  
  7. \savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
  8. {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
  9. {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
  10. {1992,1810},{1994,1750},{1998,2176},{2002,2399}]
  11. \centering
  12. \psset{algebraic,xAxisLabel={{\AA}r},yAxisLabel={Antal deltagere}}
  13.  
  14. \begin{psgraph}[Ox=1920,Dx=10,Dy=500]{->}(1920,0)(2015,2750){13.5cm}{8.1cm}
  15. \dataplot[plotstyle=dots,dotstyle=o,fillcolor=red]{\data}
  16. \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.)
  17. \end{psgraph}
  18.  
  19. \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

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:

  1. \documentclass[danish]{article}
  2. \usepackage{babel}
  3. \usepackage{auto-pst-pdf,pst-plot}
  4.  
  5. \begin{document}
  6.  
  7. \begin{figure}
  8. \savedata{\data}[{1924,300},{1928,510},{1932,310},{1936,880},{1948,700},
  9. {1952,730},{1956,820},{1960,660},{1964,1100},{1968,1160},
  10. {1972,1220},{1976,1130},{1980,1070},{1984,1300},{1988,1430},
  11. {1992,1810},{1994,1750},{1998,2176},{2002,2399}]
  12. \centering
  13. \psset{algebraic,xAxisLabel={\AA r},yAxisLabel={Antal deltagere}}
  14. \begin{pspicture}(10cm,6cm)
  15. \begin{psgraph}[Ox=1920,Dx=10,Dy=500]{->}(1920,0)(2015,2750){10cm}{6cm}
  16. \dataplot[plotstyle=dots,dotstyle=o,fillcolor=red]{\data}
  17. \psplot[linecolor=blue]{1924}{1976}{15.6394*(x-1920)+303.3}
  18. \psplot[linecolor=blue]{1980}{2002}{60.793*(x-1920)-2619.99}
  19. \end{psgraph}
  20. \end{pspicture}
  21. \end{figure}
  22.  
  23. \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 8 guests