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 am having too much trouble trying to get a nice looking plot that takes latex font with gnuplot so I am trying pgfplots again.

The only trouble is that I cannot resize the plot, so that it fills half the page. I would also like the points to be smaller and don't know how to make it so. I would also like to not have to paste the data twice to get it to work. I cannot pull it from a file because pgplots seems to need titles and my file format has not the titles in it.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}


\begin{tikzpicture}[domain=0:18]
\begin{axis}[xlabel={Current $mA$}, ylabel={Voltage $mV$}]

\addplot[scatter, only marks, scatter src=\thisrow{Current},
      error bars/.cd, y dir=both, x dir=both, y explicit, x explicit, error bar style={color=mapped color}]
      table[x=Current,y=Voltage,x error=xerr,y error=yerr] {
Current Voltage xerr   yerr     
13.9900 -1.80000 0.149900 0.197300 
12.0200 -1.50000 0.130200 0.197750 
9.99000 -1.30000 0.109900 0.198050 
8.00000 -1.00000 0.0900000 0.198500 
6.02000 -0.800000 0.0702000 0.198800 
4.01000 -0.500000 0.0501000 0.199250 
2.00000 -0.300000 0.0300000 0.199550 
0.00000 0.00000 0.0100000 0.200000 
-2.00000 0.300000 -0.0100000 0.200450 
-4.00000 0.500000 -0.0300000 0.200750 
-6.02000 0.800000 -0.0502000 0.201200 
-8.00000 1.10000 -0.0700000 0.201650 
-10.0000 1.30000 -0.0900000 0.201950 
-12.0300 1.50000 -0.110300 0.202250 
-13.9800 1.80000 -0.129800 0.202700 
};
   \addplot[no markers,color=blue,forget plot] table [x=Current, y={create col/linear regression={y=Voltage}}]{
   Current Voltage xerr   yerr     
13.9900 -1.80000 0.149900 0.197300 
12.0200 -1.50000 0.130200 0.197750 
9.99000 -1.30000 0.109900 0.198050 
8.00000 -1.00000 0.0900000 0.198500 
6.02000 -0.800000 0.0702000 0.198800 
4.01000 -0.500000 0.0501000 0.199250 
2.00000 -0.300000 0.0300000 0.199550 
0.00000 0.00000 0.0100000 0.200000 
-2.00000 0.300000 -0.0100000 0.200450 
-4.00000 0.500000 -0.0300000 0.200750 
-6.02000 0.800000 -0.0502000 0.201200 
-8.00000 1.10000 -0.0700000 0.201650 
-10.0000 1.30000 -0.0900000 0.201950 
-12.0300 1.50000 -0.110300 0.202250 
-13.9800 1.80000 -0.129800 0.202700 
}; 

\end{axis}
\end{tikzpicture}
\end{document}

graph

Update: When trying the method below: This is the file:

13.9600 -7.60000 0.149600 0.188600 
12.0100 -6.50000 0.130100 0.190250 
9.98000 -5.40000 0.109800 0.191900 
7.99000 -4.30000 0.0899000 0.193550 
6.01000 -3.30000 0.0701000 0.195050 
4.00000 -2.20000 0.0500000 0.196700 
2.00000 -1.10000 0.0300000 0.198350 
0.00000 0.00000 0.0100000 0.200000 
-2.00000 1.10000 -0.0100000 0.201650 
-3.99000 2.20000 -0.0299000 0.203300 
-6.01000 3.20000 -0.0501000 0.204800 
-7.99000 4.30000 -0.0699000 0.206450 
-9.99000 5.40000 -0.0899000 0.208100 
-12.0000 6.40000 -0.110000 0.209600 
-13.9700 7.50000 -0.129700 0.211250

graphoutcome

enter image description here

share|improve this question
    
Put your data between \pgfplotstableread{.....}{\mytable} and use that for consecutive uses. Also look for header=false,height=... options. –  percusse Jan 29 '13 at 1:00
    
Is this an answer? I've dome something but I am not sure what you mean about the header stuff, –  Magpie Jan 29 '13 at 2:12
    
Remove \usepackage{filecontents} and \begin{filecontentes}{wfn.dat} and \end{filecontents}. That package is only needed for creating example problems, when you need to include an external file in the example .tex document. If the file wfn.dat exists on your file system, you don't need filecontents. –  Jake Jan 30 '13 at 6:46
add comment

2 Answers

up vote 4 down vote accepted
  1. PGFPlots does not require data files to have headers. If there are no headers, you can refer to the columns using x index=<column number>, x error=<column number>, etc. In the linear regression options, you can set y=1 to refer to the second column.
  2. To resize the plot, you can specify the height and/or width of the plot. If you only specify one of these, the aspect ratio will be kept constant, and the plot will just be scaled. If you specify both, the aspect ratio changes.
  3. If you want the data points to be smaller, set mark size=1.5 (or something like that).
  4. If you don't want colours for the markers (as your question title suggests), don't use scatter, just use only marks.

A file data.csv:

13.9900 -1.80000 0.149900 0.197300 
12.0200 -1.50000 0.130200 0.197750 
9.99000 -1.30000 0.109900 0.198050 
8.00000 -1.00000 0.0900000 0.198500 
6.02000 -0.800000 0.0702000 0.198800 
4.01000 -0.500000 0.0501000 0.199250 
2.00000 -0.300000 0.0300000 0.199550 
0.00000 0.00000 0.0100000 0.200000 
-2.00000 0.300000 -0.0100000 0.200450 
-4.00000 0.500000 -0.0300000 0.200750 
-6.02000 0.800000 -0.0502000 0.201200 
-8.00000 1.10000 -0.0700000 0.201650 
-10.0000 1.30000 -0.0900000 0.201950 
-12.0300 1.50000 -0.110300 0.202250 
-13.9800 1.80000 -0.129800 0.202700 

The .tex file:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}


\begin{tikzpicture}[domain=0:18]
\begin{axis}[xlabel={Current mA}, ylabel={Voltage mV}]

\addplot[mark size=1.5, only marks,
      error bars/.cd,
        y dir=both, y explicit,
        x dir=both, x explicit
      ]
      table [x error index=2, y error index=3]
      {data.csv};
   \addplot[no markers,color=blue,forget plot]
    table [y={create col/linear regression={y=1}}]
    {data.csv}; 

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
why is there need to print the data when referencing the file? –  Magpie Jan 29 '13 at 21:20
    
@Magpie: Do you mean the \begin{filecontents}...\end{filecontents} section? That's only a way for LaTeX to pretend that that file exists in the file system. In a real application, you'd have the data.csv in the file system, and you wouldn't use the filecontents bit. –  Jake Jan 29 '13 at 21:22
    
Oh. that was confusing me. I tried using file cotents with just the file but it wouldn't read the error columns? –  Magpie Jan 29 '13 at 22:06
    
@Magpie: is everything working now? –  Jake Jan 29 '13 at 22:07
    
No I probably shouldn't have clicked yes. I get what you are saying though I did it another way because I can't get that way to work. I'd like to be able to though becuase it's annoying having to post the file contents, I just tried your code as is. I'll unclick the answer and show you what I get from it and what's in the file -maybe you will know straight away what I have done wrongly. –  Magpie Jan 29 '13 at 22:26
show 3 more comments

This is a solution I have found but it would be preferable to use Jake's (if I can get it working, that is)

\pgfplotstableread{
Current Voltage xerr   yerr     
13.9800 7.50000 0.149800 0.211250 
12.0300 6.50000 0.130300 0.209750 
10.0000 5.40000 0.110000 0.208100 
8.00000 4.30000 0.0900000 0.206450 
6.02000 3.20000 0.0702000 0.204800 
4.00000 2.20000 0.0500000 0.203300 
2.00000 1.10000 0.0300000 0.201650 
0.00000 0.00000 0.0100000 0.200000 
-2.00000 -1.10000 -0.0100000 0.198350 
-3.99000 -2.20000 -0.0299000 0.196700 
-6.01000 -3.30000 -0.0501000 0.195050 
-8.00000 -4.30000 -0.0700000 0.193550 
-9.99000 -5.40000 -0.0899000 0.191900 
-12.0300 -6.50000 -0.110300 0.190250 
-13.9700 -7.40000 -0.129700 0.188900 
}\wfp

\pgfplotstablecreatecol[linear regression={ymode=log}]{regression}{\wfp}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[
    scale=2.2,
    xmin=-15,xmax=15,xlabel={Current $mA$}, ylabel={Voltage $mV$},title={$V_H$ against current for p-type Germanium}
]

\addplot [only marks, black, error bars/.cd, y dir=both, x dir=both, y explicit, x explicit, error bar style={color=mapped color}]
      table[x=Current,y=Voltage,x error=xerr,y error=yerr]{\wfp}; % plot the data
%\addplot [no markers, domain=0:18] {exp(\intercept+\slope*x)}; 
\addplot [color=blue, domain=-15:15, mark=none] {-0.00143422 + 0.537833 *\x};



\end{axis}
\end{tikzpicture}
\caption{The}
\end{figure}

enter image description here

The resizing was acheived using the scale=2.2 with the package \usepackage[hmargin=2cm,vmargin=2cm]{geometry}

share|improve this answer
add comment

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.