to_latex#
- to_latex(Gbunch, pos='pos', tikz_options='', default_node_options='', node_options='node_options', node_label='node_label', default_edge_options='', edge_options='edge_options', edge_label='edge_label', edge_label_options='edge_label_options', caption='', latex_label='', sub_captions=None, sub_labels=None, n_rows=1, as_document=True, document_wrapper='\\documentclass{{report}}\n\\usepackage{{tikz}}\n\\usepackage{{subcaption}}\n\n\\begin{{document}}\n{content}\n\\end{{document}}', figure_wrapper='\\begin{{figure}}\n{content}{caption}{label}\n\\end{{figure}}', subfigure_wrapper=' \\begin{{subfigure}}{{{size}\\textwidth}}\n{content}{caption}{label}\n \\end{{subfigure}}')[source]#
Return latex code to draw the graph(s) in
GbunchThe TikZ drawing utility in LaTeX is used to draw the graph(s). If
Gbunchis a graph, it is drawn in a figure environment. IfGbunchis an iterable of graphs, each is drawn in a subfigure environment within a single figure environment.If
as_documentis True, the figure is wrapped inside a document environment so that the resulting string is ready to be compiled by LaTeX. Otherwise, the string is ready for inclusion in a larger tex document using\includeor\inputstatements.- Parameters:
- GbunchNetworkX graph or iterable of NetworkX graphs
The NetworkX graph to be drawn or an iterable of graphs to be drawn inside subfigures of a single figure.
- posstring or list of strings
The name of the node attribute on
Gthat holds the position of each node. Positions can be sequences of length 2 with numbers for (x,y) coordinates. They can also be strings to denote positions in TikZ style, such as (x, y) or (angle:radius). If a dict, it should be keyed by node to a position. If an empty dict, a circular layout is computed by TikZ. If you are drawing many graphs in subfigures, use a list of position dicts.- tikz_optionsstring
The tikzpicture options description defining the options for the picture. Often large scale options like
[scale=2].- default_node_optionsstring
The draw options for a path of nodes. Individual node options override these.
- node_optionsstring or dict
The name of the node attribute on
Gthat holds the options for each node. Or a dict keyed by node to a string holding the options for that node.- node_labelstring or dict
The name of the node attribute on
Gthat holds the node label (text) displayed for each node. If the attribute is “” or not present, the node itself is drawn as a string. LaTeX processing such as"$A_1$"is allowed. Or a dict keyed by node to a string holding the label for that node.- default_edge_optionsstring
The options for the scope drawing all edges. The default is “[-]” for undirected graphs and “[->]” for directed graphs.
- edge_optionsstring or dict
The name of the edge attribute on
Gthat holds the options for each edge. If the edge is a self-loop and"loop" not in edge_optionsthe option “loop,” is added to the options for the self-loop edge. Hence you can use “[loop above]” explicitly, but the default is “[loop]”. Or a dict keyed by edge to a string holding the options for that edge.- edge_labelstring or dict
The name of the edge attribute on
Gthat holds the edge label (text) displayed for each edge. If the attribute is “” or not present, no edge label is drawn. Or a dict keyed by edge to a string holding the label for that edge.- edge_label_optionsstring or dict
The name of the edge attribute on
Gthat holds the label options for each edge. For example, “[sloped,above,blue]”. The default is no options. Or a dict keyed by edge to a string holding the label options for that edge.- captionstring
The caption string for the figure environment
- latex_labelstring
The latex label used for the figure for easy referral from the main text
- sub_captionslist of strings
The sub_caption string for each subfigure in the figure
- sub_latex_labelslist of strings
The latex label for each subfigure in the figure
- n_rowsint
The number of rows of subfigures to arrange for multiple graphs
- as_documentbool
Whether to wrap the latex code in a document environment for compiling
- document_wrapperformatted text string with variable
content. This text is called to evaluate the content embedded in a document environment with a preamble setting up TikZ.
- figure_wrapperformatted text string
This text is evaluated with variables
content,captionandlabel. It wraps the content and if a caption is provided, adds the latex code for that caption, and if a label is provided, adds the latex code for a label.- subfigure_wrapperformatted text string
This text evaluate variables
size,content,captionandlabel. It wraps the content and if a caption is provided, adds the latex code for that caption, and if a label is provided, adds the latex code for a label. The size is the vertical size of each row of subfigures as a fraction.
- Returns:
- latex_codestring
The text string which draws the desired graph(s) when compiled by LaTeX.
See also