0

I have a scatter plot that needs some modifications. Why isn't O being typeset with the command \node (origin) at ($(O)+(225:10pt)$) {$O$};? I would like O to be typeset in the same font as the tick mark label 10 on the x-axis and the tick mark label 120 on the y-axis. I do not want the line drawn through the points, and I don't want the grid lines drawn from 10 and 120. Along the y-axis, I would like the label to be printed on two lines - "Candy Bars" on the second line.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}

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

\begin{document}

\begin{tikzpicture}

\begin{axis}[grid=major, title=\textbf{George's Unsold Candy Bars\unboldmath},
    ylabel = Number of Unsold Candy Bars,
    xlabel = Number of Days,
    xmin=0,xmax=11,ymin=0,ymax=130,
    xtick={\empty},ytick={\empty},
    extra x ticks={10},
    extra x tick labels={10},
    extra y ticks={120},
    extra y tick labels={120},
    yticklabel style={anchor=east},]

\addplot plot coordinates{(0,120) (1,108) (2,96) (3,84) (4,72) (5,60) (6,48) (7,36) (8,24) (9,12) (10,0)};
\coordinate (O) at (0,0);
\node (origin) at ($(O)+(225:10pt)$) {$O$};

\end{axis}

\end{tikzpicture}

\end{document}

2 Answers 2

1

First of all, why using the extra ticks? Just use the regular ones, the result is the same. You also used \addplot plot, but the second plot is not needed. About your questions:

Why isn't O being typeset with the command \node (origin) at ($(O)+(225:10pt)$) {$O$};?

You need to place the command outside of the axis environment. Besides, stating the coordinate for one command is superfluous, just say (0,0).

I would like O to be typeset in the same font as the tick mark label 10 on the x-axis and the tick mark label 120 on the y-axis.

In your example you wrote $O$, which is not going to be the same for two reasons: It's in math mode, and you wrote an O, the letter and not 0, the number zero. Changing to 0 will use the same font.

I do not want the line drawn through the points, and I don't want the grid lines drawn from 10 and 120. Along the y-axis, I would like the label to be printed on two lines - "Candy Bars" on the second line.

The option only marks only plots the coordinate points. The grid lines can be removed by saying grid=none while you had grid=major. And for the new line in the y axis label, just add \\ where you want the line to break.

Output

figure 1

Code

\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{calc}

\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}

\begin{axis}[grid=none, align=center, title=\textbf{George's Unsold Candy Bars},
    ylabel = Number of Unsold\\Candy Bars,
    xlabel = Number of Days,
    xmin=0,xmax=11,
    ymin=0,ymax=130,    
    xtick={10},
    ytick={120},
    yticklabel style={anchor=east},]

\addplot[only marks] coordinates{(0,120) (1,108) (2,96) (3,84) (4,72) (5,60) (6,48) (7,36) (8,24) (9,12) (10,0)};
\end{axis}

\node (origin) at ($(0,0)+(225:10pt)$) {0};
\end{tikzpicture}
\end{document}
2
  • Thanks for the explanations. Before I posted this question, I did have ylabel = Number of Unsold\\Candy Bars, but I did not have align=center, in the options.
    – user74973
    Commented Jun 2, 2015 at 17:49
  • I don't want the tick marks on the top and right sides of the square. Can only these tick marks be removed? If they cannot be removed, can you remove the top and right sides and replace the left side withylabel=$y$, and ylabel style={at={(ticklabel* cs:1)},anchor=south west} and replace the bottom with xlabel=$x$, and xlabel style={at={(ticklabel* cs:1)},anchor=north west},?
    – user74973
    Commented Jun 2, 2015 at 17:49
0

Here is code that renders a scatter plot that is closer to what I want. The tick marks at 10 on the x-axis and 120 on the y-axis seem to be obscured by the dots for the scatter plot. More importantly, the labels for the axes are missing.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}

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

\begin{document}

\begin{tikzpicture}


\begin{tikzpicture}

\begin{axis}[grid=none, align=center, title=\textbf{George's Unsold Candy Bars},
    ylabel = Number of Unsold \\ Candy Bars,
    xlabel = Number of Days,
    xmin=0,xmax=11,ymin=0,ymax=130,
    xtick={10},ytick={120},
    yticklabel style={anchor=east},
    axis on top,axis lines=middle,
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south east}
    ]

\addplot[only marks] coordinates{(0,120) (1,108) (2,96) (3,84) (4,72) (5,60) (6,48) (7,36) (8,24) (9,12) (10,0)};

\end{axis}

\coordinate (O) at (0,0);
\node (origin) at ($(O)+(225:10pt)$) {$0$};

\end{tikzpicture}

\end{document}
1
  • @Maarten Dhondt May you help me with the display rendered from this code? There are only two typical modifications that I want. First, I want labels on the axes. In the axis environment, I have align=center,, ylabel = Number of Unsold \\ Candy Bars,, and xlabel = Number of Days,. Why are the labels not being printed? Second, I want to make the dots representing the data to be a bit smaller so that the two tick marks can be visible.
    – user74973
    Commented Jun 5, 2015 at 12:35

You must log in to answer this question.

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