# How to increase/fit the width of x-axis to fit all points in pgfplots?

This is my code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[scale only axis,
symbolic x coords={v1,v3,v4,v7,v8,v9,v10,v11,v15,v16,v17,v18,v20,v23,v25,v27,v28,v29,v30,v31},
symbolic y coords={1,2,3,Not in top 3},
xtick=data,
ytick=data]
(v1,3)
(v3,1)
(v4,1)
(v7,1)
(v8,Not in top 3)
(v9,2)
(v10,1)
(v11,2)
(v15,1)
(v16,1)
(v17,Not in top 3)
(v18,1)
(v20,Not in top 3)
(v23,2)
(v25,1)
(v27,Not in top 3)
(v28,1)
(v29,1)
(v30,Not in top 3)
(v31,1)
};
\end{axis}
\end{tikzpicture}

\end{document}


This is how it looks:

How to make the plot fit properly?

-
One way is width=0.75\linewidth, x tick label style={font=\tiny},, but the result is not very good. Must be a better way. –  Peter Grill Feb 20 '13 at 4:43
@user1280282: Do you want a way to automatically scale the plot width to fit all your labels? Or are you asking for a way to do it manually? –  Jake Feb 20 '13 at 6:58
Manual way is also fine.. –  tikzlearner Feb 20 '13 at 7:03

What do you think of adding:

enlarge x limits=-1, %hack to plot on the full x-axis scale
width=13cm, %set bigger width
height=6cm,
yticklabel style={anchor= east,rotate=45 }, %rotate y-ticks to have even more space


EDIT: You could also rotate the x-ticks to make them more readable.

The full code:

\begin{tikzpicture}
\begin{axis}[scale only axis,
enlarge x limits=-1,
symbolic x coords={v1,v3,v4,v7,v8,v9,v10,v11,v15,v16,v17,v18,v20,v23,v25,v27,v28,v29,v30,v31},
symbolic y coords={1,2,3,Not in top 3},
width=13cm,
height=6cm,
yticklabel style={anchor= east,rotate=45 },
xtick=data,
ytick=data]
(v1,3)
(v3,1)
(v4,1)
(v7,1)
(v8,Not in top 3)
(v9,2)
(v10,1)
(v11,2)
(v15,1)
(v16,1)
(v17,Not in top 3)
(v18,1)
(v20,Not in top 3)
(v23,2)
(v25,1)
(v27,Not in top 3)
(v28,1)
(v29,1)
(v30,Not in top 3)
(v31,1)
};
\end{axis}
\end{tikzpicture}

-