Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass[a4paper]{article}
- usepackage{tikz}
- usepackage{pgfplots}
- pgfplotsset{compat=1.11}
- usepgfplotslibrary{fillbetween}
- usetikzlibrary{
- arrows,
- decorations,
- calc,
- intersections,
- matrix,
- decorations.pathmorphing,
- spy,
- }
- newcommandsignplot[4]{ % start end points signStart
- % Draws a line between #1 and #2
- draw[shorten <= -1cm, shorten >= -1cm] (#1) -- (#2);
- % Checking whether the first sign is positive or not
- ifnum1=#4relax % It starts positive
- % Cycle between the list of points given at which the sign changes
- foreach x in #3{
- % Drawing circles with the text
- coordinate (A) at (#1);
- coordinate (B) at (x,0);
- filldraw[fill=black,draw=black] (A-|B) circle(2pt)
- node[below]{x};
- % Going through 0->x (where x = current coordinate) with a step of 0.3
- foreach c in {0,0.3,0.6,...,x}{
- coordinate (A1) at ($(A)+(-1cm,0)$);
- % Drawing the + sign above the line
- coordinate (C) at ($(A1-|B)+(0,0.2)$);
- coordinate (D) at (c,0);
- node at (C-|D) {+};
- }
- }
- else % Same as above
- foreach x in #3{
- coordinate (A) at (#1);
- coordinate (B) at (x,0);
- filldraw[fill=black,draw=black] (A-|B) circle(2pt)
- node[below]{x};
- foreach c in {0.3,0.6,...,x}{
- % Just drawing the - sign below
- coordinate (C) at ($(A-|B)+(0,-0.2)$);
- coordinate (D) at (c,0);
- node at (C-|D) {-};
- }
- }
- fi
- }
- begin{document}
- begin{tikzpicture}
- coordinate (O) at (0,0);
- coordinate (A) at (5,0);
- signplot{O}{A}{{0,3}}{0}
- end{tikzpicture}
- end{document}
Add Comment
Please, Sign In to add comment