Api Docs:

RFigure.test()[source]

a test docstring

Returns:Nothing

Unless mentionned otherwise, the code is written by R. Dessalles (Grumpfou). Published under license GNU General Public License v3.0. Part of the RFigure project.

class RFigure.RFigureCore.RFigureCore(d=None, i=None, c=None, file_split='# RFIG_start_instructions', filepath=None)[source]

This si the RFigureCore core class.

__init__(d=None, i=None, c=None, file_split='# RFIG_start_instructions', filepath=None)[source]

This function will save the figure into a propper way, in order to open it again.

Parameters:
  • d (dict) – dictionary that contain the variable useful to plot the figure.
  • i (str or func) – instructions, string that contains the python code to create the figure. If it is a function, takes the source of the function.
  • c (str) – commentaries where the user can describe the figure.
  • file_split (str) – file_split it the string that will separate the instructions. What will be bollow the first instance of will be considered as the instructions. If file_split string is not encountered, keeps the whole instructions
  • filepath (str) – the path to the file (useful for the local header and to directly save the file)
  • frame (int)

Example

>>> import RFigure,numpy
... X = numpy.arange(0,10,0.1)
... Y = numpy.cos(X)
... i = "plot(X,Y)" # the instrucutions
... d = dict(X=X,Y=Y) # the data to display
... c = "This is a test" # the commentaries associate with the figures
... rf = RFigure.RFigureCore(d=d,i=i,c=c)
... rf.show() # execute the instructions to be sure it works
... rf.save(filepath='./Test.rfig3') # only save the rfig3 file
... rf.save(filepath='./Test.rfig3',fig_type='pdf') # save the rfig3 file as well as the pdf associated
clean_instructions()[source]

Ensure that the instruction are idented at the the first level.

execute(print_errors=False)[source]

The method executes the instructions (no show at the end). Proceed in four steps: 1. executes the general header file RFigure/RFigureConfig/RFigureHeader.py 2. executes the local header file ./.RFigureHeaderLocal.py 3. updates the locals with the rfig variables self.dict_variables 4. executes the rfig instructions self.instructions

Parameters:print_errors (bool) – if True, will print the errors rather than raise them (to avoid some troubles with PyQt5)
formatExt(filepath=None, ext=None, replace_current=True)[source]

Changes/adds if necessary the extension to the filepath. Update the attribute self.filepath accordingly

Parameters:
  • filepath (str) – the filepath to format.
  • ext (str) – the extension (the dot needs to be included). By default, takes self.ext.
  • replace_current (bool) – if True, then replace the current self.filepath by the one obtained
Returns:

filepath (str) – the new filepath with the updated file extension

formatName(filepath=None, replace_current=True)[source]

Format the filename under the format: “path/Figure_YYYYMMDD_foo.rfig3” where foo is the current filename. If the filpath is already under this format, do not change it. It updates the attribute self.filepath.

Parameters:
  • filepath (str) – the filepath to format, by default takes self.filename
  • replace_current (bool) – if True, then replace the current self.filepath by the one obtained
Returns:

filepath (str) – the new filepath with the updated file name

Example

>>> rf = RFigureCore(filpath='./foo/faa.rfig3')
>>> rf.formatName()
"./foo/Figure_20181201_faa.rfig3"
>>> rf.formatName(filepath='./foo/fii.rfig3')
"./foo/Figure_20181201_fii.rfig3"
>>> rf.formatName(filepath='./foo/Figure_20181201_fuu.rfig3')
"./foo/Figure_20181201_fuu.rfig3"

(with each time, 20181201 corresponding to the curent date)

classmethod load(filepath)[source]

Return a RFigureCore instance that had openned the rfigure.

Parameters:filepath (str) – the path of the rfigure to load
Returns:rfig (RFigureCore) – The RFigureCore instance created.
open(filepath)[source]

Open the rfig file from filepath

Parameters:filepath (str) – the path of the rfigure. Set the attribute self.filepath to this value
save(filepath=None, fig_type=None, check_ext=True)[source]

Will save the figure in a rfig file.

Parameters:
  • filepath (str) – The filepath where to save the figure. Adds the extension if necessary. If None, search the attribute self.filepath (if self.filepath also None, raise an error). Is not None, set self.filepath to the new file path.

  • fig_type (None, str or list(str)) –

    if not None, will save the figure in the corresponding format (if it

    is a list, will save in several formats). Should be in [‘pdf’, ‘eps’, ‘png’, ‘svg’].

  • check_ext (bool) – if True, adds if necessary the extension to filepath

Returns:

paths (list of str) – the paths of the files created/edited (i.e. the rfig file and the pdf/png/etc. that represents the figure)

savefig(fig_path, fig_type='png')[source]

Method that will save the figure with the corresponding extention.

Parameters:
  • fig_path (str) – The path of where to save the figure the figure.

  • fig_type (None, str or list(str)) –

    if not None, will save the figure in the corresponding format (if it

    is a list, will save in several formats). Should be in [‘pdf’, ‘eps’, ‘png’, ‘svg’].

Returns:

paths (list of str) – the paths of the files created/edited (i.e. the rfig file and the pdf/png/etc. that represents the figure)

show(print_errors=False)[source]

Method that execute the code instructions and adds the matplotlib.pyplot.show() statement at the end.

Parameters:print_errors (bool) – if True will print the errors rather than raise them (to avoid some troubles with PyQt5)
static update(fig_path, d=None, i=None, c=None, mode='append', fig_type=None)[source]

Update the dict_variables of an already existing file:

Parameters:
  • fig_path (str) – The rfig2 file to update.

  • d (dict) – The dict to update with.

  • i (str) – The instricution to update with.

  • c (str) – The commentary to update with.

  • mode (str in [‘append’,’replace’]) –

    if mode==’append’:

    will update the dict and add instructions and commentaries to the allready instructions and commentaries

    if mode==’replace’:

    will replace the dict, instructions and commentaries

Returns:

rfig (RFigureCore instance) – the RFigureCore instance with updated dict_variables

class RFigure.RFigureMagics.MyArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]
exception ArgumentParserError[source]
error(message: string)[source]

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

class RFigure.RFigureMagics.RFigureMagics(shell=None, **kwargs)[source]
rfig_curdate(line)[source]

Magic function that assign a different current date that will be used when formatting the names. Equivalent to change the value of RFigureCore.CURDATE.

Examples

(in IPython/Jupyter)

>>> %rfig_save --format_name Test
... # Will save in the file `Figure_YYYYMMDD_Test.rfig3` where YYYYMMDD
... # stands for the current date.
... plt.plot(np.arange(10),np.arange(10))
>>> %rfig_crudate 19990909
... # set the curent date to `'19990909'`
>>> %rfig_save --format_name Test
... # Will save in the file `Figure_19990909_Test.rfig3`
... plt.plot(np.arange(10),np.arange(10))
rfig_format(line)[source]

Magic function that assign a different format that will be used when formatting the names. Equivalent to change the value of RFigureCore.FORMAT.

Examples

(in IPython/Jupyter)

>>> %rfig_save --format_name Test
... # Will save in the file `Figure_YYYYMMDD_Test.rfig3` where YYYYMMDD
... # stands for the current date.
... plt.plot(np.arange(10),np.arange(10))
>>> %rfig_format Fig-%Y-%m-%d_%s
... # set the curent date to `'Fig-%Y-%m-%d_%s'`
>>> %rfig_save --format_name Test
... # Will save in the file `Fig_YYYY-MM-DD_Test.rfig3`
... plt.plot(np.arange(10),np.arange(10))
rfig_list_var(line, cell)[source]

usage: %%rfig_list_var [–help] [dict_variable]

Detects the variables in the code of the cell.

positional arguments:
dict_variable the variable name of the dictionary in which will be stored
the variables detected in the cell. If none is given, only prints its keys.
optional arguments:
--help, -h show this help message and exit

Examples

(in IPython/Jupyter)

>>> a = np.arange(0,10,.1)
... b = np.cos(a)
>>> %%rfig_list_var
... plot(a,b)
We determined the RFigure variables to be: `a`, `b`
>>> %%rfig_list_var a_dict
... plot(a,b)
We determined the RFigure variables to be: `a`, `b`
>>> print(a_dict.keys())
dict_keys(['a','b'])
rfig_load(line)[source]

usage: %%rfig_load [–help] [-d D] [-i I] [-c C] [filepath]

Will load a RFigure in the Jupyter notebook.

positional arguments:
filepath Path of the file to open.
optional arguments:
--help, -h show this help message and exit
-d D the variable name of the dictionary in which will be stored the variables of the RFigure. If none is given, import in the notebook locals.
-i I the variable name of the string in which will be stored the instructions of the RFigure. If none is given, create a new cell filled with the instructions. Also checks if the magic %pylab has been executed. If not, it adds the command %pylab at the begining of the instructions
-c C the variable name of the string in which will be stored the commentaries of the RFigure.

Examples

(in IPython/Jupyter)

>>> # Opens the RFigure Test.rfig3:
... # 1) import its variables in the notebook locals
... # 2) checks that %pylab is imported (if not addd it)
... # 3) create a new cell with the instructions
... %rfig_load "Test.rfig3"
>>> # Opens the RFigure Test.rfig3:
... # 1) stores the variables in `ddd`
... # 2) stores the instructions in `iii`
... # 3) stores the commentaries in `ccc`
... %rfig_load -i iii -c ccc -d ddd "Test.rfig3"
rfig_save(line, cell)[source]
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 [‘pdf’, ‘eps’, ‘png’, ‘svg’]

Examples

(in IPython/Jupyter)

>>> import numpy as np
... a = np.arange(0,10,.1)
... b = np.cos(a)
... comment = "A comment"
... diction = {'a':a,'b':1/a}
>>> %%rfig_save Test
... # search the variables in the instructions, no comment and save in pdf
... plt.plot(a,b)
>>> %%rfig_save -c comment Test
... # search the variables in the instructions, with a comment and save in pdf
... plt.plot(a,b)
>>> %%rfig_save --fig_type png Test
... # search the variables in the instructions, no comment and save in png
... plt.plot(a,b)
>>> %%rfig_save -d diction Test
... # specify other variables, no comment, save in pdf
... plt.plot(a,b)
>>> %%rfig_save --format_name Test
... # search the variables in the instructions, format the filename
... plt.plot(a,b)
RFigure.RFigureMisc.RTextWrap(text, nb=79, sep='\n', begin='')[source]

Will return the text properly wrapped

Parameters:
  • text (str) – the textg to wrap
  • nb (int) – the limit at which we wrap the text
  • sep (str) – the char that seperate the paragraphs
  • begin (str) – the char that should begin each line
Returns:

wrapped_text (str) – the wrapped version of the text

RFigure.RFigureMisc.decoDocFormatting(*args)[source]

Decorator that will format the documentation of the function by using the formatting like doc%args

Parameters:args (objects) – the argument to put in the formatting
Returns:func (fonction) – the function with the correct documentation
RFigure.RFigureMisc.decoSetDoc(doc)[source]
Function dedicated to be used as a decorator that set the documentation
doc to the function func.
Parameters:
  • func (fonction) – the function to set the documentation to
  • doc (str) – the documentation to attach to the function
Returns:

func (fonction) – the function with the given documentation

RFigure.RFigurePickle.isAuthorized(v)[source]

Function that determines if the object is authorised to be saved in a rpickle file. It checks recusivally (if a list or a dict) that the object can indeed be represented in a rpickle file.

Parameters:v (any object) – the object to check
Returns:res (bool) – the status of the object
RFigure.RFigurePickle.load(filepath)[source]

Load the RPickle file of filepath

Parameters:filepath (path to the file to load)
Returns:
  • objets (list or dict) – the saved objects
  • commentaries (str) – the commentaries stored in the file
  • version (str) – the version string stored in the file
RFigure.RFigurePickle.object_to_txt(objects, imports)[source]

Function that will transform any object in its string version

Parameters:
  • objects (in [<class ‘int’>, <class ‘list’>, <class ‘bool’>, <class ‘dict’>, <class ‘float’>, <class ‘str’>, <class ‘tuple’>, <class ‘numpy.ndarray’>, <class ‘numpy.dtype’>, <class ‘numpy.int8’>, <class ‘numpy.int16’>, <class ‘numpy.int32’>, <class ‘numpy.int64’>, <class ‘numpy.float16’>, <class ‘numpy.float32’>, <class ‘numpy.float64’>, <class ‘complex’>, <class ‘numpy.complex64’>, <class ‘numpy.complex128’>, <class ‘numpy.datetime64’>, <class ‘numpy.timedelta64’>, <class ‘numpy.bool_’>]) – the object to represent as a string
  • imports (list of str) – list of all the libraries needed to define the object (will be updated insitus)
  • Returns
  • res (str) – the string representation of the object
RFigure.RFigurePickle.save(objects, filepath, commentaries='', version=None, ext='.rpk2')[source]

Function that will save the given objects in a rpickle file.

Parameters:
  • objects (list of dict) – the object to save (can be a list or a dict if needed).
  • filepath (str) – the place where to save the sile, if has no extension, it will take the one of the class.
  • commentaries (str) – string that contains commentaries about the thing
  • version (str) – the version of the software that should use the pickle.
  • ext (str) – the file extension (the dot should be included)