21

I am using matlab2tikz to produce plots in latex. The default tick settings produce very dense ticks, making the axes look ugly. I know that I can use something like

/pgfplots/xtick={0, 1, ... 3}

to manually set the tick positions. However, I am constantly modifying the plot data, and it is annoying to have to go in and change the tick positions manually each time. This is especially annoying when I have subplots where each plot uses a different range, so I can't use the matlab2tikz extraAxisOptions parameter to change the ticks in MATLAB, since this would apply the same ticks to each subplot.

Here is an example (sorry, I don't know TikZ well enough to make this more minimal):

http://pastebin.com/B2GKyRNb

When I compile this, the y axis has five ticks, and the x axis has ticks every 0.2. I would like to reduce the density in such a way that it scales automatically with the range of the axis as well as the size of the plot (like MATLAB does).

Any help would be greatly appreciated!

2
  • Welcome to TeX.sx! Jan 28, 2013 at 20:22
  • 2
    I know that this here is not an answer, but it may help others visiting this knowledge base: pgfplots offers xtick distance=1 as of version 1.13. This is also an alternative to xtick={0,1,...,3}, although it is only useful in conjunction with a special plot. The answer of @Jake is more general and fits this use-case here. Jan 13, 2016 at 19:59

1 Answer 1

26

You can use \pgfplotsset{try min ticks=3} in your TeX document to allow PGFPlots to use only three ticks for an axis (the default is 4), and max space between ticks=50pt to allow more space between the tick marks (the default is 35):

3
  • +1. I have setup all of my PGFPlots like this. I find the default settings can look a little bit cramped sometimes.
    – onewhaleid
    Mar 6, 2015 at 2:26
  • 1
    According to the pgfplots documentation, you have to leave out the pt, i.e., max space between ticks=50. Jan 19, 2016 at 16:56
  • This solution is gold! I was stuck with the limited number of ticks in smaller graphs.
    – SKPS
    Dec 1, 2016 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .