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'm getting quite frustrated with my lack of pgfplot understanding and was hoping somebody could help me figure out how to get more readily readable/understandable x axis tick marks. I have the following: Bad axis

But what I want is the x axis to read more clearly like 2e-3 or even 0.002 instead of the 10^-2.6 which is hardly intuitive. I tried playing around with "x tick label" but it didn't seem to have any influence on the plot! Thanks in advance for your help!

This is the code I'm using to create the graph:

\documentclass[]{standalone}
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.6}

\begin{document}

\pgfplotsset{every axis plot}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{loglogaxis}
    [clip marker paths=true,legend cell align=left,
    legend style={
        at={(0.5,-0.2)},
        anchor=north},
    legend columns=2,
    xlabel=field amplitude,
    ylabel=losses,
    xmin=2e-3, xmax=5e-2,
    ymin=1e-4, ymax=1e-1,
    grid=major
    ]

    \addplot [sharp plot,mark=none, color=black,dotted] table[skip first n=2,x expr=\thisrow{x},y expr=\thisrow{y}]
        {Comp_DataSim.eins.table};

\end{loglogaxis}
\end{tikzpicture}

\end{document}

I uploaded the data here: http://pastebin.com/1zzgtQ2f

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

You can play around with the pgf/number format/ key described in the manual of pgfplotstable to achieve various results.

Two examples :

\documentclass[]{standalone}
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.6}

\begin{document}

\pgfplotsset{every axis plot}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{loglogaxis}
    [clip marker paths=true,legend cell align=left,
    legend style={
        at={(0.5,-0.2)},
        anchor=north},
    legend columns=2,
    xlabel=field amplitude,
    ylabel=losses,
    xmin=2e-3, xmax=5e-2,
    ymin=1e-4, ymax=1e-1,
    xtick={2e-3,5e-3,1e-2,2e-2,5e-2},
    xticklabel style={/pgf/number format/.cd,fixed,precision=3},
    xticklabel={%
      \pgfmathfloatparsenumber{\tick}%
      \pgfmathfloatexp{\pgfmathresult}%
      \pgfmathprintnumber{\pgfmathresult}%
    },
    grid=major
    ]

  % Below is a dummy plot so that the MWE is self-contained
  % Anyway, only the axes matter, right? :-)
  \addplot+ coordinates
  {(0,1)
  (5,2)
  (10,3)
  (50,4)
  (100,5)
  (500,6)
  (1000,7)
  (5000,8)
  (10000,9)
  (100000,10)}
;

\end{loglogaxis}
\end{tikzpicture}

\end{document}

enter image description here

\documentclass[]{standalone}
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.6}

\begin{document}

\pgfplotsset{every axis plot}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{loglogaxis}
    [clip marker paths=true,legend cell align=left,
    legend style={
        at={(0.5,-0.2)},
        anchor=north},
    legend columns=2,
    xlabel=field amplitude,
    ylabel=losses,
    xmin=2e-3, xmax=5e-2,
    ymin=1e-4, ymax=1e-1,
    xtick={2e-3,5e-3,1e-2,2e-2,5e-2},
    xticklabel style={/pgf/number format/sci},
    xticklabel={%
      \pgfmathfloatparsenumber{\tick}%
      \pgfmathfloatexp{\pgfmathresult}%
      \pgfmathprintnumber{\pgfmathresult}%
    },
    grid=major
    ]

  \addplot+ coordinates
  {(0,1)
  (5,2)
  (10,3)
  (50,4)
  (100,5)
  (500,6)
  (1000,7)
  (5000,8)
  (10000,9)
  (100000,10)}
;

\end{loglogaxis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Thanks, that is exactly what I was hoping for! Perfect! :) –  Meferdati Jan 25 '13 at 18:10
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.