In [1]:
import RFigure,os
filepath_testfile  = "Test.rfig3"
if "tests" in os.listdir():
    filepath_testfile = os.path.join("tests",filepath_testfile)
assert os.path.exists(filepath_testfile)

In [2]:
%load_ext RFigure.RFigureMagics

In [3]:
import numpy as np
X = np.arange(0,10,.1)
Y = np.cos(X)
c = "This is a comment"
d = dict(X=X,Y=1/X) # another variable dictionary


/home/dessalles/Programmation/Python/Project_RFigure/noGithub/myenv/lib/python3.6/site-packages/ipykernel_launcher.py:5: RuntimeWarning: divide by zero encountered in true_divide
  """

In [4]:
%%rfig_save -h
pass


usage: %%rfig_save [--help] [--format_name] [-d D] [-c C]
                   [--fig_type FIG_TYPE]
                   [filepath]

Will save a RFigure, whose instructions are the code written in the remaining of the cell.

positional arguments:
  filepath              Path of the file.

optional arguments:
  --help, -h            show this help message and exit
  --format_name, -fn    Format the name of the file as Figure_YYYYMMDD_foo
                        where YYYYMMDD stands for the date. `foo` will be the
                        file names. If the file name is already under this
                        format, do notiong.
  -d D                  Dictionary of the locals in the rfigure file. If not
                        specified, guess from the instructions.
  -c C                  Comments associated to the file
  --fig_type FIG_TYPE, -ft FIG_TYPE
                        extension of the figure, should be in ['eps', 'pdf',
                        'png']

Examples (in IPython/Jupyter):

In[1]:
> import numpy as np
> a = np.arange(0,10,.1)
> b = np.cos(a)
> comment = "A comment"
> diction = {'a':a,'b':1/a}

In[2]:
> %%rfig_save Test
> # search the variables in the instructions, no comment and save in pdf
> plt.plot(a,b)

In[3]:
> %%rfig_save -c comment Test
> # search the variables in the instructions, with a comment and save in pdf
> plt.plot(a,b)

In[4]:
> %%rfig_save --fig_type png
> # search the variables in the instructions, no comment and save in png
> plt.plot(a,b)

In[5]:
> %%rfig_save -d diction Test
> # specify other variables, no comment, save in pdf
> plt.plot(a,b)

In[5]:
> %%rfig_save --format_name Test
> # search the variables in the instructions, format the filename
> plt.plot(a,b)
Out[4]:
True

In [5]:
%%rfig_save Test.rfig3
# search the variables in the instructions, no comment and save in pdf
plt.plot(X,Y)


We determined the RFigure variables to be: `Y`, `X`
Pickle success
========== END SAVE =========

In [6]:
%%rfig_save -c c Test.rfig3
# search the variables in the instructions, put the comment of the variable `c`
plt.plot(X,Y)


We determined the RFigure variables to be: `Y`, `X`
Pickle success
========== END SAVE =========

In [7]:
%%rfig_save -c c -d d Test.rfig3
# search the variables in the instructions, put the comment of the variable `c`
plt.plot(X,Y)


Pickle success
========== END SAVE =========

In [8]:
%%rfig_save -c "'This is another comment'" Test.rfig3
# search the variables in the instructions, put the comment of the variable `c`
plt.plot(X,Y)


We determined the RFigure variables to be: `Y`, `X`
Pickle success
========== END SAVE =========

In [9]:
%%rfig_save -c "'This is another comment'" -fn Test.rfig3
# search the variables in the instructions, put the comment of the variable `c`
plt.plot(X,Y)


We determined the RFigure variables to be: `Y`, `X`
Pickle success
========== END SAVE =========

In [10]:
# Assert the files with formated name and removes it
import os
from RFigure.RFigureMisc import RDateDisplay

f =  "Figure_%s_Test"%RDateDisplay.cur_date()
print(f)
assert os.path.exists(f+".pdf")
os.remove(f+".pdf")
assert os.path.exists(f+".rfig3")
os.remove(f+".rfig3")


Figure_20190122_Test

In [11]:
%%rfig_save -c "'This is another comment'" -ft eps Test.rfig3
# search the variables in the instructions, put the comment of the variable `c`
plt.plot(X,Y)


We determined the RFigure variables to be: `Y`, `X`
Pickle success
========== END SAVE =========

In [12]:
# Assert the eps files has been created and remove it
assert os.path.exists("Test.eps")
os.remove("Test.eps")

In [ ]:
%%rfig_save -i "plt.plot(X,Y)" -c "'This is another comment'" -ft None Test.rfig3

In [17]:
%rfig_load -i iii -c ccc Test.rfig3


Success instructions
rf.instructions <class 'str'>
rf.dict_variables <class 'dict'>

In [21]:
assert ccc == 'This is another comment'
assert iii == 'plt.plot(X,Y)'

In [ ]: