Please consider the following MWE. The same code is in another document with a larger preamble, so maybe my problem with the misaligned xticklabels is because of conflicting packages.

The first screenshot shows the results of the MWE and the second how it looks like when compiled with a larger preamble.

Note: For the MWE I did not include special formatting (e.g. colours, dashing etc).

EDIT By the way: If you take a look at the data in dataLevelerConverter2.dat you will see that there is a Kalenderwoche 42. However, in the first screenshot it seems that the xticks start with Kalenderwoche 43.

You are probably supplying the tick labels manually and the remaning ones are left empty because it runs out of tick labels on the list. Without any other info we can't say much.
–
percusseOct 30 '12 at 17:07

@percusse: The code for the plot is for both, the MWE and the larger tex-document the same. I do not supply any special information for the tick labels. (Hope I understood you correctly)
–
JohnOct 30 '12 at 17:09

@John: Thanks for putting together a complete compilable example. The only thing missing is that you need to include enough of the preamble so that the MWE here reproduce the problem. Not sure how we can possibly guess what other settings are causing the problem.
–
Peter GrillOct 30 '12 at 17:18

1

You don't need to read the xticklabels from the table. Just set x=Kalenderwochen in the addplot options. If you need more ticks, add try min ticks=9 in the axis options. This will change the yticks too, so you can set ytick={0,500,...,1500} if you want to preserve the yticks.
–
LuigiOct 30 '12 at 19:37

1

@Luigi: "Kalenderwochen" translates to "calendar weeks", so these will wrap around, so just using x=Kalenderwochen might work for this concrete example, but is not the "proper" thing to do for this kind of data.
–
JakeOct 30 '12 at 20:08

2 Answers
2

Luigi's suggestion of using Kalenderwochen as the x-coordinate directly is a good idea in this concrete example. However, it won't work if Kalenderwochen indeed contains labels (numeric or otherwise): In John's text label example, the xtick={0,...,9} has to be set explicitly. Usually, one could just use xtick=data, but that only works if there are no nans in the first plot.

So, for the rare case where you need to provide labels from a table but can't use xtick=data to make sure the ticks and ticklabels are synchronised, here's a style xtick from table that works analogously to xticklabels from data:

This approach has the drawback that you're always using all ticks and ticklabels, instead of letting PGFPlots determine the appropriate number of ticks. To fix this, you can set

@Jake There is one problem with your approach. If you lower the width to, for instance 6cm, the tick labels get to close/overlap. How must one change your code so that LaTeX only plots such a number of tick labels so that they do not overlap. (e.g. with width=6cm it would be better to have only {42,44,...,1} as ticklabels.
–
JohnNov 27 '12 at 16:28

1

@John: Fair point. I've added a different approach that allows you to use PGFPlots normal tick placement algorithm or to manually select which ticks are placed.
–
JakeNov 27 '12 at 16:45

Did you solve the problem in your question? By the way, you don't need the first column in your table: you can simply use x expr=\coordindex in the addplot options, along with xtick={0,...,8} (you have to load the pgfplotstable package too).
–
LuigiOct 31 '12 at 8:38