6

I'm quite new to drawing graphs. I have the following table:

\begin{tabular}{rrrr}
\firstrow Frequency/[Hz] & $V_{pp}$/[V] & $V_{rms}$ DMM/[V] & $V_{rms}$ scope/[V] \\
50          & 0.800     & 0.28135       & 0.283 \\
100         & 0.800     & 0.28145       & 0.283 \\
200         & 0.808     & 0.28150       & 0.286 \\
500         & 0.808     & 0.28152       & 0.286 \\
1000        & 0.808     & 0.28153       & 0.286 \\
2000        & 0.808     & 0.28153       & 0.286 \\
5000        & 0.808     & 0.28157       & 0.286 \\
10000       & 0.808     & 0.28140       & 0.286 \\
100000      & 0.808     & 0.28027       & 0.286 \\
200000      & 0.816     & 0.27254       & 0.288 \\
300000      & 0.808     & 0.24229       & 0.286 \\
400000      & 0.816     & 0.19153       & 0.288 \\
500000      & 0.800     & 0.14047       & 0.283 \\
\end{tabular}

I wish to make a scattered plot graph out of this to turn out like something like this (graph made in Excel):

enter image description here

How do I recreate that graph directly in LaTeX? The x axis is the Frequency and the y axis are the values from column 3 and 4, so the V_rms columns.

2
  • 2
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Have you looked at pgfplots? That seems to be a popular package for plotting things. (Well for plotting graphs - not sure about novels or allotments.) – cfr Oct 8 '14 at 0:38
  • I did have a look at the pgfplots, but couldn't figure out how to get the below answer on my own. It feels rather complicated to me as of now. I still consider myself quite new to latex. Only been playing with it for 4 weeks or so, and then mostly for text or math documents, some tables and circuit drawings have been made for boyfriend too, but this felt a bit too advanced for me right now to figure out alone in the timeframe I got. – Ahana Oct 8 '14 at 6:36
7

This would get you started

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotstableread[header=false]{
50          0.800     0.28135       0.283 
100         0.800     0.28145       0.283 
200         0.808     0.28150       0.286 
500         0.808     0.28152       0.286 
1000        0.808     0.28153       0.286 
2000        0.808     0.28153       0.286 
5000        0.808     0.28157       0.286 
10000       0.808     0.28140       0.286 
100000      0.808     0.28027       0.286 
200000      0.816     0.27254       0.288 
300000      0.808     0.24229       0.286 
400000      0.816     0.19153       0.288 
500000      0.800     0.14047       0.283 
}\mytable
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[xminorgrids,
ymax=1,
ymin=0.1,
legend entries={$V_{rms}$ DMM [V],$V_{rms}$ Scope[V]},
legend style={at={(axis description cs:1.05,0.5)},anchor=west,draw=none},
log base 10 number format code/.code={% There was an options for this?
  \pgfkeys{/pgf/fpu}\pgfmathparse{10^#1}%
  \pgfmathprintnumber[fixed,1000 sep=]{\pgfmathresult}%
  }
]
\addplot[blue!60,only marks,mark=diamond*] table[x index=0,y index=2]\mytable;
\addplot[green,
  only marks,
  mark=square*,
  mark size=3pt,
] table[x index=0,y index=3]\mytable;
\end{loglogaxis}
\end{tikzpicture}
\end{document}

enter image description here

4
  • This looks beautiful! Is there a way to get this wider, so that last point is still within the graph? I guess preferably I'd like this with the width=\textwidth if that is possible. Except from that, this is just a beauty! :D Thank you :) – Ahana Oct 8 '14 at 6:34
  • @ahana check out the width and height options for the size issues. You already mentioned one but if you use only width it keeps the aspect ratio. You need both to resize. – percusse Oct 8 '14 at 7:17
  • cool, I got it to work, how do I add the [ and ] into the label? It is complaining with I try to do: \[Hz\] – Ahana Oct 8 '14 at 19:18
  • @ahana remove the backslashes and put inside a brace pair. – percusse Oct 8 '14 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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