[Tex/LaTex] How to make the ugly graph look nice

graphspgfplots

I am 2 weeks into using LaTex so pardon my noob-ness 🙂

I have some data in my physics lab that I need to graph, which I have in a tab-delimited text file called current-force.txt. I graphed the data using pgfplots. Here is the file contents:

current force
0.00    0.00
0.50    1.28E-03
1.00    2.75E-03
1.50    4.02E-03
2.00    5.40E-03
2.50    6.67E-03
3.00    8.04E-03
3.50    9.42E-03
4.00    1.07E-02

Here is my sample LaTex document:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{float}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amstext}

\begin{document}
    \begin{figure}[H]
        \centering
    \begin{tikzpicture}

        \begin{axis}[
            title={Magnetic Force as a function of Applied Current},
            xlabel=$I$ (\si{\A}),
            ylabel=$\vec{F}_{\text{m}}$ (\si{\N}),
            minor x tick num=1,
            grid=both,
            ]

            \addplot[red, mark=*] table[col sep=tab]{current-force.txt};
        \end{axis}

    \end{tikzpicture}
    \end{figure}
\end{document}

I added the grid and the minor ticks on the x-axis, but I just don't know what would make this graph look nicer. One think I also find really ugly is the positioning for the axis multiplier for the y-axis, how would you guys approach this?

This is what the graph looks like after typesetting:

enter image description here

Best Answer

Here are some points I would change, other may disagree on them.

  • I prefer to have the ticks out side.
  • I hate grids. You will rarely find them in physical publications.
  • I would use simply mN as unit for the force.
  • The x axis range should not be larger than the data range.
  • The caption makes the title superfluous

This is how I would do it.

screenshot

and the code

\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{float}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amstext}
\usepackage{filecontents}
\pgfplotsset{compat=newest}

\begin{filecontents}{current-force.txt}
current force
0.00    0.00
0.50    1.28E-03
1.00    2.75E-03
1.50    4.02E-03
2.00    5.40E-03
2.50    6.67E-03
3.00    8.04E-03
3.50    9.42E-03
4.00    1.07E-02
\end{filecontents}

\pgfplotsset{
    physics/.style = {
        minor x tick num=1,
        xtick pos=left,
        ytick pos=left,
        enlarge x limits=false,
        every x tick/.style={color=black, thin},
        every y tick/.style={color=black, thin},
        tick align=outside,
        xlabel near ticks,
        ylabel near ticks,
        axis on top,        
    }
}

%
% Dirty hack from Koji
% see http://tex.stackexchange.com/a/91645/3061
%
\makeatletter
\def\pgfplots@drawticklines@INSTALLCLIP@onorientedsurf#1{}%
%\def\pgfplots@drawgridlines@INSTALLCLIP@onorientedsurf#1{}%
\makeatother

\begin{document}
    \begin{figure}[H]
        \centering
    \begin{tikzpicture}
        \begin{axis}[
            physics,
            xlabel=$I$ (\si{\ampere}),
            ylabel=$F_{\text{m}}$ (\si{\milli\newton}),
            ymin = 0,
            y filter/.code={
                \pgfmathmultiply{\pgfmathresult}{1E3}
            }
           ]
            \addplot[red, mark=*] table {current-force.txt};
        \end{axis}
    \end{tikzpicture}
    \caption{Magnetic force as a function of the applied current.}
    \end{figure}
\end{document}
Related Question