Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. #+BEGIN_SRC ipython :session :file plot2.png :exports both
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. L = 6
  6. x = np.linspace(0, L)
  7. ncolors = len(plt.rcParams['axes.color_cycle'])
  8. shift = np.linspace(0, L, ncolors, endpoint=False)
  9. for s in shift:
  10. plt.plot(x, np.sin(x + s), 'o-')
  11. plt.xlabel('x-axis')
  12. plt.ylabel('y-axis')
  13. plt.title('title')
  14.  
  15. plt.show()
  16. #+END_SRC
  17.  
  18. #+RESULTS:
  19. [[file:plot2.png]]
  20.  
  21. #+BEGIN_SRC ipython :session :file plot3.png :exports both
  22. from mpl_toolkits.mplot3d import axes3d
  23. import matplotlib.pyplot as plt
  24. from matplotlib import cm
  25.  
  26. fig = plt.figure()
  27. ax = fig.gca(projection='3d')
  28. X, Y, Z = axes3d.get_test_data(0.05)
  29. ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
  30. cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
  31. cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
  32. cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
  33.  
  34. ax.set_xlabel('X')
  35. ax.set_xlim(-40, 40)
  36. ax.set_ylabel('Y')
  37. ax.set_ylim(-40, 40)
  38. ax.set_zlabel('Z')
  39. ax.set_zlim(-100, 100)
  40.  
  41. plt.show()
  42. #+END_SRC
  43.  
  44. #+RESULTS:
  45. [[file:plot3.png]]
  46.  
  47. #+TBLNAME: data_table
  48. |------------------+----+---+----|
  49. | date | x | y | z |
  50. |------------------+----+---+----|
  51. | <2016-06-15 Wed> | 1 | 1 | 1 |
  52. | <2016-06-16 Thu> | 2 | 2 | 2 |
  53. | <2016-06-17 Fri> | 4 | 3 | 3 |
  54. | <2016-06-18 Sat> | 8 | 4 | 4 |
  55. | <2016-06-19 Sun> | 16 | 5 | 30 |
  56. | <2016-06-20 Mon> | 32 | 6 | 40 |
  57. |------------------+----+---+----|
  58.  
  59. #+BEGIN_SRC ipython :session :file plot.png :exports both :var table=data_table
  60. import matplotlib.pyplot as plt
  61. import numpy as np
  62. import pandas as pd
  63. %matplotlib inline
  64.  
  65. df = pd.DataFrame(table[1:], columns=table[0])
  66. df.plot()
  67. #+END_SRC
  68.  
  69. #+RESULTS:
  70. [[file:plot.png]]
  71.  
  72. #+BEGIN_SRC ipython :session :exports both
  73. def foo(x):
  74. return x + 9
  75.  
  76. [foo(x) + 7 for x in range(7)]
  77. #+END_SRC
  78.  
  79. #+RESULTS:
  80. | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
  81.  
  82. #+BEGIN_SRC python
  83. def foo(x):
  84. return x + 9
  85.  
  86. [foo(x) + 7 for x in range(7)]
  87.  
  88. #+END_SRC
  89.  
  90. #+RESULTS:
  91. : None
  92.  
  93. #+BEGIN_SRC latex
  94. \LaTeX
  95. #+END_SRC
  96.  
  97. #+RESULTS:
  98. #+BEGIN_LaTeX
  99. \LaTeX
  100. #+END_LaTeX
  101.  
  102. #+name: test_plot_png
  103. #+header: :exports results :file test.png
  104. #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 400
  105. #+header: :fit yes :noweb yes :headers '("\\usepackage{tikz}")
  106. #+begin_src latex :exports results :file test.png
  107. library("tikzDevice")
  108. tikz(console=TRUE, width=4, height=4)
  109. plot(rnorm(100), rnorm(100))
  110. dummy <- dev.off()
  111. #+end_src
  112.  
  113. #+RESULTS: test_plot_png
  114. #+BEGIN_LaTeX
  115. [[file:test.png]]
  116. #+END_LaTeX
  117.  
  118. #+begin_src latex
  119. \LaTeX
  120. #+end_src
  121.  
  122. #+RESULTS:
  123. #+BEGIN_LaTeX
  124. \LaTeX
  125. #+END_LaTeX
  126.  
  127. #+begin_src latex :file latex-logo.pdf :imagemagick :packages '(("" "tikz")) :border 1em
  128. % Define block styles
  129. \usetikzlibrary{shapes,arrows}
  130. \tikzstyle{astate} = [circle, draw, text centered, font=\footnotesize, fill=blue!25]
  131. \tikzstyle{rstate} = [circle, draw, text centered, font=\footnotesize, fill=red!25]
  132.  
  133. \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=2.8cm, semithick]
  134. \node [astate] (1) at (0,0) {1};
  135. \node [astate] (2) at (1,0) {2};
  136. \node [rstate] (3) at (2,0) {3};
  137. \path (1) edge [bend left] node {b} (2)
  138. (2) edge node {b} (3)
  139. (2) edge [bend left] node {a} (1)
  140. (3) edge [loop above] node {(a, b)} (3);
  141. \end{tikzpicture}
  142. #+end_src
  143.  
  144. #+RESULTS:
  145. #+BEGIN_LaTeX
  146. [[file:latex-logo.pdf]]
  147. #+END_LaTeX
  148. #+name: test_plot_png
  149. #+header: :exports both :file test.png
  150. #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 400
  151. #+header: :fit yes :noweb yes :headers '("\\usepackage{tikz}")
  152. #+begin_src latex
  153. % Define block styles
  154. \usetikzlibrary{shapes,arrows}
  155. \tikzstyle{astate} = [circle, draw, text centered, font=\footnotesize, fill=blue!25]
  156. \tikzstyle{rstate} = [circle, draw, text centered, font=\footnotesize, fill=red!25]
  157.  
  158. \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=2.8cm, semithick]
  159. \node [astate] (1) at (0,0) {1};
  160. \node [astate] (2) at (1,0) {2};
  161. \node [rstate] (3) at (2,0) {3};
  162. \path (1) edge [bend left] node {b} (2)
  163. (2) edge node {b} (3)
  164. (2) edge [bend left] node {a} (1)
  165. (3) edge [loop above] node {(a, b)} (3);
  166. \end{tikzpicture}
  167. #+end_src
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement