figurefirst package¶
Submodules¶
figurefirst.figurefirst_user_parameters module¶
figurefirst.mpl_functions module¶
-
figurefirst.mpl_functions.
add_mpl_patch
(ax, patchname, *args, **kwargs)¶ wrapper for these two calls: patch = matplotlib.patches.Patch() ax.add_artist(patch)
-
figurefirst.mpl_functions.
adjust_spines
(ax, spines, spine_locations={}, smart_bounds=True, xticks=None, yticks=None, linewidth=1, spine_location_offset=None, default_ticks=False, tick_length=5, color='black', direction='in')¶ ax - matplotlib axis object spines - list of spines to include, e.g. [‘left’, ‘bottom’] spine_locations - dict of spine locations, e.g. {‘left’: 5, ‘bottom’: 5}. Defaults to user_parameters. smart_bounds - if True, stop spine at first and last ticks xticks - list of locations for the xticks, e.g. [0, 5, 10] yticks - same as xticks, for y axis linewidth - width of spine and tick marks spine_location_offset - where to place spines. Overrides spine_locations if not None. default_ticks - if True, skip smart bounds and tick placement. NEcessary for loglog plots to work properly.
-
figurefirst.mpl_functions.
fix_mpl_svg
(file_path, pattern='miterlimit:100000;', subst='miterlimit:1;')¶ used to fix problematic outputs from the matplotlib svg generator, for example matplotlib creates exceptionaly large meterlimis
-
figurefirst.mpl_functions.
kill_all_labels
(layout)¶
-
figurefirst.mpl_functions.
kill_all_spines
(layout)¶
-
figurefirst.mpl_functions.
kill_labels
(ax)¶
-
figurefirst.mpl_functions.
kill_spines
(ax)¶
-
figurefirst.mpl_functions.
set_fontsize
(fig, fontsize)¶ For each text object of a figure fig, set the font size to fontsize fig can also be an axis object
-
figurefirst.mpl_functions.
set_spines
(layout)¶
figurefirst.svg_to_axes module¶
-
class
figurefirst.svg_to_axes.
FFAxis
(tagnode, **kwargs)¶ Bases:
figurefirst.svg_to_axes.FFItem
Stores the data requred for the creation of a matplotlib axes as specified by the layout
-
class
figurefirst.svg_to_axes.
FFFigure
(tagnode, **kwargs)¶ Bases:
figurefirst.svg_to_axes.FFGroup
,object
Represents a matplotlib figure
-
class
figurefirst.svg_to_axes.
FFGroup
(tagnode, **kwargs)¶ Bases:
figurefirst.svg_to_axes.FFItem
,object
used to collect groups objects that will be translated into matplotlib objects eg. axes and figures, x,y w and h is the collective x,y width and height of all the enclosed objects
-
class
figurefirst.svg_to_axes.
FFItem
(tagnode, **kwargs)¶ Bases:
dict
,object
base class for figurefirst objects that will be converted to matplotlib objects eg. axes
-
class
figurefirst.svg_to_axes.
FFSVGGroup
(tagnode, **kwargs)¶ Bases:
figurefirst.svg_to_axes.FFItem
,object
used to collect groups of svg items
-
class
figurefirst.svg_to_axes.
FFSVGItem
(tagnode)¶ Bases:
figurefirst.svg_to_axes.FFItem
,object
base class for svg objects that figurefirst will manipulate in the native svg form eg. text and paths. These objects can be used to change the style of tagged graphics in the document
-
frmtstyle
()¶
-
load_style
()¶
-
-
class
figurefirst.svg_to_axes.
FFSVGPath
(tagnode)¶ Bases:
figurefirst.svg_to_axes.FFSVGItem
,object
represents a svg path, currently figurefirst is unable to change the dimensions of the path, and the x, y, w, h attributes are meaningless placeholders
-
frmtstyle
()¶
-
load_style
()¶
-
-
class
figurefirst.svg_to_axes.
FFSVGText
(tagnode)¶ Bases:
figurefirst.svg_to_axes.FFSVGItem
,object
represents a svg text object, you can change the text, font as well as styling x,y contain the orign of the text box, height and with are currently not implemented since that would require parsing the font info
-
load_style
()¶
-
load_text
()¶
-
-
class
figurefirst.svg_to_axes.
FFTemplateTarget
(tagnode, **kwargs)¶ Bases:
figurefirst.svg_to_axes.FFFigure
,object
represtents the target of a template. The all the axes within the template figure will be scaled to fit within the template target box
-
class
figurefirst.svg_to_axes.
FigureLayout
(layout_filename, autogenlayers=True, make_mplfigures=False, dpi=300, hide_layers=('Layer 1', ))¶ Bases:
object
-
add_attribute_to_layer
(layer_name, attribute, value)¶
-
append_figure_to_layer
(fig, fflayername, cleartarget=False, save_traceback=False, notes=None)¶ inserts a figure object, fig, into an inkscape SVG layer, the layer fflayername should be taged with a figurefirst:targetlayer tag. if fflayername is not found then a targetlayer is generated so long as self.autogenlayers is set to True, the default. If cleartarget is set to True then the contents of the target layer will be removed, usefull for itterative figure design.
- save_traceback - save the traceback stack to the figure’s xml. This makes it easy to find out what function was
- used to generate the figure. Also saves date modified
- notes - string, which is added as an attribute to the xml of the layer. Helpful if you want to embed info into the
- layers for future reference.
-
apply_mpl_methods
()¶ apply valid mpl methods to figure
-
apply_svg_attrs
(svg_items_to_update='all')¶ applies attributes to svgitems eg. lw stroke ect… need to call this function before saving in order to propegate changes to svgitems
- svg_items_to_update - (optional) - provide a list of the svgitem tags that you wish to have updated. Default is ‘all’, which updates all the svgitems,
- which could reset svgitems whose attributes were not set since the last call to ‘None’.
-
clear_fflayer
(fflayername)¶ If inserting mpl figure into a mpl target layer that has stuff in it, e.g. old mpl data, use this function to clear the layer of any children except the figurefirst:targetlayer node.
-
create_new_targetlayer
(layer_name)¶
-
from_userx
(x, dst)¶ transfrom from user coords to dst coords
-
from_usery
(y, dst)¶ same as userx but for y coords,not used in this version
-
get_figure_element_by_name
(name)¶ finds the xmlnode with a given figurefirst:name tag
-
get_outputfile_layers
()¶ returns dictionary of layers in teh output file
-
insert_figures
(fflayername='mpl_layer', cleartarget=False)¶ takes a reference to the matplotlib figure and saves the svg data into the target layer specified with the xml tag <figurefirst:targetlayer> this tag must have the attribute figurefirst:name = fflayername
-
load_pathspecs
()¶ parses pathspec objects from the layout document
-
load_svgitems
()¶ loads the svgitems from the layout document
Save layout.svg, data.svg, figure, axis information into each mpl axis
-
make_group_tree
()¶ does the work of traversing the svg document and building the representation of figures, groups and axes, this needs to be done before self.makemplfigures can generate the matplotlib figurs
-
make_mplfigures
(hide=False, axes_order={})¶ generates matplotlib figures from the tree of parsed FFFigure and FFGroup, FFTemplatetargets
axes_order: {‘figure1’: [top_axis, next_axis, etc.], ‘figure2’: []}. Dictionary of the figures, that point to the list of axes, starting with the axis that should be on top first. Any axes not listed will end up on the bottom.
-
pass_xml
(gid, key, value)¶ pass key, value pair xml pair to group with ID gid gid should contain prefix ‘figurefirst:’ to ensure uniqueness usage: layout.pass_xml(gid,’jessyink:effectIn’, ‘name:appear;order:1;length:800’)
-
save
(filename, hidelayers=(), targetlayer=None, fix_meterlimt=True)¶ convenience function, inserts layers and then calls wirte_svg to save
-
set_layer_visibility
(inkscape_label='Layer 1', vis=True, gid=None)¶ appled to the output svg usefull to hide the design layers on the newly created figures
-
to_svg_buffer
(fig)¶ writes a matplotlib figure into a stringbuffer and returns the buffer
-
write_fifidata
(info, *args, **kwargs)¶ Write arbitrary data to the figurefirst data file info - list of strings, e.g. [‘title’, ‘description 1’, ‘description 2’] args - data you want to store in the data file
-
write_svg
(output_filename)¶ writes the current output_xml document to output_filename
-
-
class
figurefirst.svg_to_axes.
LineSpec
(*args, **kwargs)¶ Bases:
figurefirst.svg_to_axes.PathSpec
-
mplkwargs
()¶
-
-
class
figurefirst.svg_to_axes.
PatchSpec
(*args, **kwargs)¶ Bases:
figurefirst.svg_to_axes.PathSpec
-
mplkwargs
()¶
-
-
figurefirst.svg_to_axes.
extractTreeByType
(node, searchType)¶ walk a nested dictionary and pop the items of a certain type from the dictionary
-
figurefirst.svg_to_axes.
filterTreeByType
(node, searchType)¶
-
figurefirst.svg_to_axes.
flatten_dict
(d)¶ unrap a nested dict, d, returns a new dictionary with that have tuples as keys that specify the path through the original dictionary tree to the leaf. e.g. {‘l1key’: {‘l2key1’:item1,’l2key2’:item2}} will become {(‘l1key’,’l2key1’):item1,(‘l1key’,’l2key2’):item2}
-
figurefirst.svg_to_axes.
flatten_list
(container)¶
-
figurefirst.svg_to_axes.
get_elements_by_attr
(xml_node, attribute, value)¶ helper function for xml trees when using minidom
-
figurefirst.svg_to_axes.
get_transforms
(node, tlist=[])¶ get the list of transforms applied to a given node, walking up the svg tree to fill tlist. Pass an empyt list to call
-
figurefirst.svg_to_axes.
parse_transform
(transform_str)¶ convert transforms into transformation matrix
-
figurefirst.svg_to_axes.
repar
(val, unit)¶ reparse a value and unit into a string for writing into an svg
-
figurefirst.svg_to_axes.
tounit
(in_unit, dst_unit)¶ returns a float with the value of string s in the units of dst
-
figurefirst.svg_to_axes.
upar
(unit_st)¶ Parse unit_st into num (float), unit (string) pair