# How to change format of xticklabel when loaded from table

I have the following code

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents}{testdata.dat}
6.3e-05 0.8767984145412976 0.6
0.000125 12.85965577546382 9.970000000000001
0.00025 16.95140970189756 13.76
0.0005 14.61328253838453 12.13
0.001 21.24630316052836 17.76
0.002 33.45255040918443 27.81
0.004 0 17.97
0.0056 0 0
0.008 0 0
0.0112 0 0
0.016 0 0
0.0224 0 0
0.0315 0 0
\end{filecontents}

\usetikzlibrary{calc}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
ybar=0pt,
/pgf/bar width=5pt,
bar cycle list,
width=6cm,
height=2cm,
scale only axis,
xmajorgrids,
ymin=0, ymax=100,
ymajorgrids,
tick label style={font=\scriptsize},
x tick label style={/pgf/number format/sci},
xticklabels from table={\datatable}{0}
]
\end{axis}
\end{tikzpicture}
\end{document}


which gives me this plot

Now instead of the fixed format for the xticklabels I want the scientific format and want an xtick on every delivered coordinate. How do I achieve this? I tried it with x tick label style={/pgf/number format/sci} but that did not help.

Update:

To have every xtick I had to use the option xtick=data.

• So you are trying to avoid the overlap? – percusse Jun 30 '13 at 10:07
• No that's not the problem, I can use rotate=90. I just want the label in the scientific format like 1.25e-4 and so on. – Reza Jun 30 '13 at 10:12
• The key xticklabels from table has been introduces for symbolic data, i.e. it does not apply the number printer at all. Might be a feature request. Do you need xticklabels from table? – Christian Feuersänger Jun 30 '13 at 10:37
• Yes that would be great to have such a feature – Reza Jun 30 '13 at 10:52
• @ChristianFeuersänger I would benefit from this feature too. – Alfred M. Jul 8 '13 at 9:28

1 xtick=data means the x-axis from data.

2 But xticklabels from table means the x-axis format from data.

That is, if you want the legend read from \datatable, use first method.

The example from PGFplots Official website shows the difference in two methods. The example 323(or in Manual version 1.8 page 302)

    xmin=-4.7124, xmax=4.7124,
xtick={-4.7124,-1.5708,...,10},
xticklabels={$-\frac{3}{2} \pi$,$-\pi/2$,$\pi/2$,$\frac{3}{2} \pi$},


Note that xtick refers to values, and xticklabels refers to format.

So if I change your code,xticklabels from table={\datatable}{0} to xtick=data, it's done. But it is ugly then.

• The idea is that number printing is bypassed when labels are loaded from table. For example, if I had an extra column just for the labels then your solution wouldn't work since xticks and the labels would be different – percusse Aug 29 '13 at 10:48
• Could you explain more about "extra column just for the labels"? I don't get it. – selwyndd21 Aug 30 '13 at 4:02
• Add another column to the table starting from 17 to 30 and I want to use it as labels using scientific notation(can be more complicated). Then xtick trick doesn't work. That's why it's a feature request given in the comments. – percusse Aug 30 '13 at 8:07