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 have the following.

screenshot in pdf reader

I'm trying to center the plot and putting \begin{center} around the TikZ image does not work.

Also I'm trying to change the units of the x-axis. The x-axis is used to represent the time. The axis is currently using seconds and I had to zoom in with xmin and xmax to get the result. Now there is a *10^(-2) at the bottom but I would like to have milliseconds or microseconds labeled at each tick.

This is the code I have now.

\begin{center}
\begin{tikzpicture}
\begin{axis}[xlabel=tijd,
    ycomb, ymin=0, ymax=4, xmin=0.0248, xmax=0.0255,
    enlarge y limits=false,
    width=15cm, height=5cm,
    tick align = outside,
    grid = major,
    %scaled x ticks = false,
    yticklabels={X, 0, settings, macroblock, picture},
    %x tick label style={/pgf/number format/fixed}
    ]
\addplot +[mark=none] table {seperatemb.dat};
\end{axis}
\end{tikzpicture}
\end{center}
share|improve this question
2  
You should make sure that your examples are compilable. In this case, you need to include a preamble (starting from \documentclass), and you should include some dummy data. –  Jake Jun 20 '12 at 14:27
1  
About the centering problem: Your plot is most likely too wide for the text area (no way of telling without knowing your documentclass and setup). You can either decrease the width of the plot, or wrap it in \begin{adjustbox}{center} (see How can I center a too wide table?), or use trim axis left in the \begin{tikzpicture}[...] options to make the y tick labels not count towards the bounding box. –  Jake Jun 20 '12 at 14:58
1  
Jake, The trim axis left option is ideal. –  Silverrocker Jun 20 '12 at 17:08

1 Answer 1

up vote 4 down vote accepted

You could transform your data to milliseconds by using x filter/.code=\pgfmathparse{#1*1000}, but a more elegant approach would be to use the units library, which is loaded using \pgfplotslibrary{units} in the preamble. You can then set x unit=s to specify that the data is in seconds, set change x base=true to allow pgfplots to transform the data, and then set x SI prefix=milli to change the units to milliseconds.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{units}


\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=tijd,
    ycomb, ymin=0, ymax=4, xmin=0.0248, xmax=0.0255,
    enlarge y limits=false,
    width=15cm, height=5cm,
    tick align = outside,
    grid = major,
    %scaled x ticks = false,
    yticklabels={X, 0, settings, macroblock, picture},
    x unit=s,
    change x base=true,
    x SI prefix=milli
    ]
\addplot +[mark=none, ultra thick] table {
0.0249 2
0.0251 1
0.0254 1
};
\end{axis}
\end{tikzpicture}


\end{document}
share|improve this answer
1  
Another quick fix is to add scaled x ticks=base 10:3, xtick scale label code/.code={ms} but siunitx is certainly better and has direct support. –  percusse Jun 20 '12 at 14:35
    
I also like the trick you did with ultra thick, this makes it alot more visible. –  Silverrocker Jun 20 '12 at 22:12

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.