5

I want to label a tick mark on the x-axis and a tick mark on the y-axis. I put a "%" before the commands in the following code so that the line could be plotted and the tick marks can be drawn. The tick mark on the y-axis is 30,042; I understand that TikZ interprets this as two numbers. I tried using $30,042$ and also got an error. How do I get 30,042 on the y-axis and 60,084 on the x-axis?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usepackage{mathtools}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}


\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-5000,xmax=70000,samples=2,
    xlabel=$x$,ylabel=$y$,
    ymin=-5000,ymax=35000,
    restrict y to domain=-5000:35000,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    extra x ticks={60084},
%    extra x tick labels={60,084},
    extra y ticks={30,042},
%    extra y tick labels={$30,042$},
    yticklabel style={anchor=east},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=200,domain=-5000:70000,blue] {-0.5*x + 30042} node[above, pos=0.75,font=\footnotesize]{$3x + 6y = 180,252$};
\end{axis}
\end{tikzpicture}


\end{document}
7
  • Unless I missed something, removing the comma from extra y ticks={30,042}, results in a plot with the tick labels that you describe. Apr 5, 2015 at 23:30
  • 1
    Use only extra x ticks={60084},extra y ticks={30042} and remove extra y tick labels={$30042$}, and extra x tick labels={60084}
    – user11232
    Apr 5, 2015 at 23:34
  • @Christopher I want the label on the y-axis to be "30,042."
    – Adelyn
    Apr 5, 2015 at 23:52
  • 1
    That is what you get: i.stack.imgur.com/rrcOA.png
    – user11232
    Apr 5, 2015 at 23:59
  • 1
    @Adelyn That's what removing the comma does as Harish Kumar has elucidated further. To remove the labels simply add extra x tick labels={\empty}, and the y-variant to the axis section. Apr 6, 2015 at 1:19

1 Answer 1

4

As discussed in the comments, the problem here is the comma in the number 30,042. This needs to be changed to 30042. By default you will get the thousand separator comma that you desire. You do not need the extra x tick labels part to get the desired output.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-5000,xmax=70000,samples=2,
    xlabel=$x$,ylabel=$y$,
    ymin=-5000,ymax=35000,
    restrict y to domain=-5000:35000,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    extra x ticks={60084},
    extra y ticks={30042},
    yticklabel style={anchor=east},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=200,domain=-5000:70000,blue] {-0.5*x + 30042} node[above, pos=0.75,font=\footnotesize]{$3x + 6y = 180,252$};
\end{axis}
\end{tikzpicture}

\end{document}

As Harish Kumar already pointed out gives:

enter image description here

As you requested it in the comments to remove the labels but leave the ticks in place you can add, extra x tick labels={\empty}, and extra y tick labels={\empty}, into the axis section. Which gives:

enter image description here

You must log in to answer this question.

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