Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. documentclass[a4paper]{article}
  2.  
  3. usepackage{tikz}
  4. usepackage{pgfplots}
  5. pgfplotsset{compat=1.11}
  6. usepgfplotslibrary{fillbetween}
  7. usetikzlibrary{
  8. arrows,
  9. decorations,
  10. calc,
  11. intersections,
  12. matrix,
  13. decorations.pathmorphing,
  14. spy,
  15. }
  16.  
  17. newcommandsignplot[4]{ % start end points signStart
  18. % Draws a line between #1 and #2
  19. draw[shorten <= -1cm, shorten >= -1cm] (#1) -- (#2);
  20.  
  21. % Checking whether the first sign is positive or not
  22. ifnum1=#4relax % It starts positive
  23. % Cycle between the list of points given at which the sign changes
  24. foreach x in #3{
  25. % Drawing circles with the text
  26. coordinate (A) at (#1);
  27. coordinate (B) at (x,0);
  28. filldraw[fill=black,draw=black] (A-|B) circle(2pt)
  29. node[below]{x};
  30. % Going through 0->x (where x = current coordinate) with a step of 0.3
  31. foreach c in {0,0.3,0.6,...,x}{
  32. coordinate (A1) at ($(A)+(-1cm,0)$);
  33. % Drawing the + sign above the line
  34. coordinate (C) at ($(A1-|B)+(0,0.2)$);
  35. coordinate (D) at (c,0);
  36. node at (C-|D) {+};
  37. }
  38. }
  39. else % Same as above
  40. foreach x in #3{
  41. coordinate (A) at (#1);
  42. coordinate (B) at (x,0);
  43. filldraw[fill=black,draw=black] (A-|B) circle(2pt)
  44. node[below]{x};
  45. foreach c in {0.3,0.6,...,x}{
  46. % Just drawing the - sign below
  47. coordinate (C) at ($(A-|B)+(0,-0.2)$);
  48. coordinate (D) at (c,0);
  49. node at (C-|D) {-};
  50. }
  51. }
  52. fi
  53. }
  54.  
  55. begin{document}
  56. begin{tikzpicture}
  57. coordinate (O) at (0,0);
  58. coordinate (A) at (5,0);
  59. signplot{O}{A}{{0,3}}{0}
  60. end{tikzpicture}
  61. end{document}
Add Comment
Please, Sign In to add comment