4

I am attempting to use the axis environment to build a simple plot line. Is it possible for tick labels to be renamed as text?

Instead of numbers I would like the month on the x-axis, and in addition, include a dollar sign on the y-axis tick label.

MWE:

\documentclass{article}

\usepackage{tikz,pgfplots}


\begin{document}
\begin{tikzpicture}
                    \begin{axis}[
                            small,
                            xlabel=Month,
                            ylabel=Dollars,
                            axis y line=left,
                            axis x line=bottom,
                            xmin=0,
                            xmax=5,
                            ymin=0,
                            ymax=6,
                            xtick={1,2,3,4},
                            ytick={2,4,6},
                            axis y discontinuity=crunch
                                ] 
                    \addplot[sharp plot] 
                        coordinates {
                            (1,2)
                            (2,2)
                            (3,4)
                            (4,4)
                                    };
                    \end{axis} 
        \end{tikzpicture}

\end{document}
Calhistorian
  • 1,093

1 Answers1

7

Add lines for setting the x and y tick labels (page 281 of the pgfplots 1.10 manual):

To deal with overlapping labels, you can rotate them with the code:

xlabel style={yshift=-1cm},
x tick label style={
      rotate=45,
      anchor=east,
      },

And in the MWE:

% arara: pdflatex
\documentclass{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        small,
        xlabel=Month,
        ylabel=Dollars,
        axis y line=left,
        axis x line=bottom,
        xmin=0, xmax=5,
        ymin=0, ymax=6,
        xtick={1,2,3,4},
        ytick={2,4,6},
        yticklabel=\$$\pgfmathprintnumber{\tick}$,%<--Here
        xticklabels={June,July,August,September},%<--Here
        xlabel style={yshift=-1cm},
        x tick label style={
            rotate=45,
            anchor=east,
        },
        axis y discontinuity=crunch
        ] 
        \addplot[sharp plot] 
            coordinates {
                (1,2)
                (2,2)
                (3,4)
                (4,4)
                };
        \end{axis} 
    \end{tikzpicture}
\end{document}
darthbith
  • 7,384