some_plots.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ##########
  2. Some plots
  3. ##########
  4. Plot 1 does not use context:
  5. .. plot::
  6. plt.plot(range(10))
  7. a = 10
  8. Plot 2 doesn't use context either; has length 6:
  9. .. plot::
  10. plt.plot(range(6))
  11. Plot 3 has length 4:
  12. .. plot::
  13. plt.plot(range(4))
  14. Plot 4 shows that a new block with context does not see the variable defined
  15. in the no-context block:
  16. .. plot::
  17. :context:
  18. assert 'a' not in globals()
  19. Plot 5 defines ``a`` in a context block:
  20. .. plot::
  21. :context:
  22. plt.plot(range(6))
  23. a = 10
  24. Plot 6 shows that a block with context sees the new variable. It also uses
  25. ``:nofigs:``:
  26. .. plot::
  27. :context:
  28. :nofigs:
  29. assert a == 10
  30. b = 4
  31. Plot 7 uses a variable previously defined in previous ``nofigs`` context. It
  32. also closes any previous figures to create a fresh figure:
  33. .. plot::
  34. :context: close-figs
  35. assert b == 4
  36. plt.plot(range(b))
  37. Plot 8 shows that a non-context block still doesn't have ``a``:
  38. .. plot::
  39. :nofigs:
  40. assert 'a' not in globals()
  41. Plot 9 has a context block, and does have ``a``:
  42. .. plot::
  43. :context:
  44. :nofigs:
  45. assert a == 10
  46. Plot 10 resets context, and ``a`` has gone again:
  47. .. plot::
  48. :context: reset
  49. :nofigs:
  50. assert 'a' not in globals()
  51. c = 10
  52. Plot 11 continues the context, we have the new value, but not the old:
  53. .. plot::
  54. :context:
  55. assert c == 10
  56. assert 'a' not in globals()
  57. plt.plot(range(c))
  58. Plot 12 opens a new figure. By default the directive will plot both the first
  59. and the second figure:
  60. .. plot::
  61. :context:
  62. plt.figure()
  63. plt.plot(range(6))
  64. Plot 13 shows ``close-figs`` in action. ``close-figs`` closes all figures
  65. previous to this plot directive, so we get always plot the figure we create in
  66. the directive:
  67. .. plot::
  68. :context: close-figs
  69. plt.figure()
  70. plt.plot(range(4))
  71. Plot 14 uses ``include-source``:
  72. .. plot::
  73. :include-source:
  74. # Only a comment
  75. Plot 15 uses an external file with the plot commands and a caption:
  76. .. plot:: range4.py
  77. This is the caption for plot 15.
  78. Plot 16 uses a specific function in a file with plot commands:
  79. .. plot:: range6.py range6