I am currently using pweave but will eventually need to switch to org mode on emacs. The biggest issue i encounter is the persistence of variables and packages imported. Here is the pweave code:
#' Import module and create a variable: import numpy as np from numpy import pi, sin x = np.arange(-2*pi, 2*pi, 0.1) print(x[0:5]) #' now we calculate sin(x) y = sin(x) print(y[0:5] #' let's graph that import matplotlib.pyplot as plt plt.plot(x,y)
That is no problem in python's pweave, but in org mode, it fails to keep the variable and its type and the imported modules from one block code to the next.
Here is the org mode attempt:
* Import numpy module and create a numpy array: #+BEGIN_SRC python :exports both import numpy as np from numpy import pi, sin x = np.arange(-2*pi, 2*pi, 0.1) return(x[0:5]) #+END_SRC * Then we calculate the sine of the numpy array created in previous block. At this stage, in pweave, both the array created and the module imported are already stored and available for use in the next block. And this is precisely where the bock code hits the road block in org mode because it did not cache the module nor the array for future use. #+BEGIN_SRC python :exports both :results file y = sin(x) import matplotlib.pyplot as plt fig = plt.figure() plt.plot(x,y) plt.savefig('~/fig.pdf') return '~/fig.pdf' #+END_SRC * finally, plotting x vs. y: #+BEGIN_SRC python :exports both return(y[0:5]) #+END_SRC
It also raises the following question: do i really need to open a new block code just for the purpose of printing y? How the previous block code handle 2 returns,the file and the print of variable y?
Anyone has a solution for this, please ?