0

I am creating a calculus sign diagram by creating a number line and labeling each side of it - the right side with an x and the left side with a y'. Above appropriate intervals I want to add plus and minus signs.

In the example below I want the x label to be on the right side of the arrowhead vertically centered with the line instead of above the line. On the left-hand side I'd like to add a y' vertically centered the same way. How can I accomplish this? By adding a node?

Above the interval [-3,0] I'd like to center a plus sign over it to show that the derivative is positive there. How can I add the plus sign like this?

I run pdflatex.

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}

\begin{document} \begin{tikzpicture}

\begin{axis}[ axis x line=middle, axis y line=none, xmin=-4.75, xmax=3.75, xlabel = $x$, xtick={-3,0,2}, width = 10cm] \addplot[ domain=-3:2, samples=800, smooth, thick, blue, ] {0}; \addplot[ domain=-4.75:-3, samples=800, smooth, thick, yellow, ] {0}; \addplot[ domain=2:3.75, samples=800, smooth, thick, yellow, ] {0}; \end{axis}

\end{tikzpicture} \end{document}

dexteritas
  • 9,161

1 Answers1

3

Adaptations

  • use (axis description cs:x,y) for positioning of x and y' (see Positioning of Pgfplot axis labels)
    • because here are multiple labels I use nodes for this (instead of xlabel)
  • use (x,y) for positioning the + sign (using the coordinates of the axis environment)
    • as hpekristiansen said in his comment (axis cs:x,y) is now the default, so one can use (x,y) instead (since pgfplots 1.11, see pgfplots manual: 2.2.1 New Optional Features)
  • add option clip=false (so the nodes outside of the plot are visible)
  • add option axis line style={yellow} (instead of manually drawing those yellow lines)
  • addplot: remove option smooth and reduce samples to 2 as it's just a straight line

Code

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}

\begin{document}

\begin{tikzpicture} \begin{axis}[ clip=false, axis x line=middle, axis y line=none, axis line style={yellow}, xmin=-4.75, xmax=3.75, xtick={-3,0,2}, width = 10cm] \addplot[ domain=-3:2, samples=2, thick, blue, ] {0}; \node[at={(axis description cs:1,.5)},anchor=west] {$x$}; \node[at={(axis description cs:0,.5)},anchor=east] {$y'$}; \node[at={(-1.5,0)},anchor=south] {$+$}; \end{axis} \end{tikzpicture}

\end{document}

Result

enter image description here

dexteritas
  • 9,161
  • To center the + over the interval I would use axis cs:-1.5,0 instead? – Ungar Linski Nov 08 '21 at 15:38
  • 1
    Oh, yeah. I must have read that wrong. I changed it. – dexteritas Nov 08 '21 at 15:39
  • 1
    +1. Do not use axis cs: -it is default since long time ago. Alternative: \path (-3,0) -- node[above]{$+$} (0,0); – hpekristiansen Nov 08 '21 at 15:47
  • 1
    I added thick to keep the axis the same thickness as the blue plot: axis line style={thick,yellow}. – Ungar Linski Nov 08 '21 at 15:56
  • @hpekristiansen axis cs: seems to work just fine. What problem does it cause? – Ungar Linski Nov 08 '21 at 16:14
  • 2
    It causes no problem. But since pgfplots 1.11 a position (x,y) is interpreted as (axis cs:x,y). Therefore, one can use that shorter notation. I added that point to my answer. (Only if you have to use an old version of pgfplots (< 1.11) you couldn't use that short notation.) – dexteritas Nov 08 '21 at 16:39