nx_latex.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. r"""
  2. *****
  3. LaTeX
  4. *****
  5. Export NetworkX graphs in LaTeX format using the TikZ library within TeX/LaTeX.
  6. Usually, you will want the drawing to appear in a figure environment so
  7. you use ``to_latex(G, caption="A caption")``. If you want the raw
  8. drawing commands without a figure environment use :func:`to_latex_raw`.
  9. And if you want to write to a file instead of just returning the latex
  10. code as a string, use ``write_latex(G, "filename.tex", caption="A caption")``.
  11. To construct a figure with subfigures for each graph to be shown, provide
  12. ``to_latex`` or ``write_latex`` a list of graphs, a list of subcaptions,
  13. and a number of rows of subfigures inside the figure.
  14. To be able to refer to the figures or subfigures in latex using ``\\ref``,
  15. the keyword ``latex_label`` is available for figures and `sub_labels` for
  16. a list of labels, one for each subfigure.
  17. We intend to eventually provide an interface to the TikZ Graph
  18. features which include e.g. layout algorithms.
  19. Let us know via github what you'd like to see available, or better yet
  20. give us some code to do it, or even better make a github pull request
  21. to add the feature.
  22. The TikZ approach
  23. =================
  24. Drawing options can be stored on the graph as node/edge attributes, or
  25. can be provided as dicts keyed by node/edge to a string of the options
  26. for that node/edge. Similarly a label can be shown for each node/edge
  27. by specifying the labels as graph node/edge attributes or by providing
  28. a dict keyed by node/edge to the text to be written for that node/edge.
  29. Options for the tikzpicture environment (e.g. "[scale=2]") can be provided
  30. via a keyword argument. Similarly default node and edge options can be
  31. provided through keywords arguments. The default node options are applied
  32. to the single TikZ "path" that draws all nodes (and no edges). The default edge
  33. options are applied to a TikZ "scope" which contains a path for each edge.
  34. Examples
  35. ========
  36. >>> G = nx.path_graph(3)
  37. >>> nx.write_latex(G, "just_my_figure.tex", as_document=True)
  38. >>> nx.write_latex(G, "my_figure.tex", caption="A path graph", latex_label="fig1")
  39. >>> latex_code = nx.to_latex(G) # a string rather than a file
  40. You can change many features of the nodes and edges.
  41. >>> G = nx.path_graph(4, create_using=nx.DiGraph)
  42. >>> pos = {n: (n, n) for n in G} # nodes set on a line
  43. >>> G.nodes[0]["style"] = "blue"
  44. >>> G.nodes[2]["style"] = "line width=3,draw"
  45. >>> G.nodes[3]["label"] = "Stop"
  46. >>> G.edges[(0, 1)]["label"] = "1st Step"
  47. >>> G.edges[(0, 1)]["label_opts"] = "near start"
  48. >>> G.edges[(1, 2)]["style"] = "line width=3"
  49. >>> G.edges[(1, 2)]["label"] = "2nd Step"
  50. >>> G.edges[(2, 3)]["style"] = "green"
  51. >>> G.edges[(2, 3)]["label"] = "3rd Step"
  52. >>> G.edges[(2, 3)]["label_opts"] = "near end"
  53. >>> nx.write_latex(G, "latex_graph.tex", pos=pos, as_document=True)
  54. Then compile the LaTeX using something like ``pdflatex latex_graph.tex``
  55. and view the pdf file created: ``latex_graph.pdf``.
  56. If you want **subfigures** each containing one graph, you can input a list of graphs.
  57. >>> H1 = nx.path_graph(4)
  58. >>> H2 = nx.complete_graph(4)
  59. >>> H3 = nx.path_graph(8)
  60. >>> H4 = nx.complete_graph(8)
  61. >>> graphs = [H1, H2, H3, H4]
  62. >>> caps = ["Path 4", "Complete graph 4", "Path 8", "Complete graph 8"]
  63. >>> lbls = ["fig2a", "fig2b", "fig2c", "fig2d"]
  64. >>> nx.write_latex(graphs, "subfigs.tex", n_rows=2, sub_captions=caps, sub_labels=lbls)
  65. >>> latex_code = nx.to_latex(graphs, n_rows=2, sub_captions=caps, sub_labels=lbls)
  66. >>> node_color = {0: "red", 1: "orange", 2: "blue", 3: "gray!90"}
  67. >>> edge_width = {e: "line width=1.5" for e in H3.edges}
  68. >>> pos = nx.circular_layout(H3)
  69. >>> latex_code = nx.to_latex(H3, pos, node_options=node_color, edge_options=edge_width)
  70. >>> print(latex_code)
  71. \documentclass{report}
  72. \usepackage{tikz}
  73. \usepackage{subcaption}
  74. <BLANKLINE>
  75. \begin{document}
  76. \begin{figure}
  77. \begin{tikzpicture}
  78. \draw
  79. (1.0, 0.0) node[red] (0){0}
  80. (0.707, 0.707) node[orange] (1){1}
  81. (-0.0, 1.0) node[blue] (2){2}
  82. (-0.707, 0.707) node[gray!90] (3){3}
  83. (-1.0, -0.0) node (4){4}
  84. (-0.707, -0.707) node (5){5}
  85. (0.0, -1.0) node (6){6}
  86. (0.707, -0.707) node (7){7};
  87. \begin{scope}[-]
  88. \draw[line width=1.5] (0) to (1);
  89. \draw[line width=1.5] (1) to (2);
  90. \draw[line width=1.5] (2) to (3);
  91. \draw[line width=1.5] (3) to (4);
  92. \draw[line width=1.5] (4) to (5);
  93. \draw[line width=1.5] (5) to (6);
  94. \draw[line width=1.5] (6) to (7);
  95. \end{scope}
  96. \end{tikzpicture}
  97. \end{figure}
  98. \end{document}
  99. Notes
  100. -----
  101. If you want to change the preamble/postamble of the figure/document/subfigure
  102. environment, use the keyword arguments: `figure_wrapper`, `document_wrapper`,
  103. `subfigure_wrapper`. The default values are stored in private variables
  104. e.g. ``nx.nx_layout._DOCUMENT_WRAPPER``
  105. References
  106. ----------
  107. TikZ: https://tikz.dev/
  108. TikZ options details: https://tikz.dev/tikz-actions
  109. """
  110. import numbers
  111. import os
  112. import networkx as nx
  113. __all__ = [
  114. "to_latex_raw",
  115. "to_latex",
  116. "write_latex",
  117. ]
  118. @nx.utils.not_implemented_for("multigraph")
  119. def to_latex_raw(
  120. G,
  121. pos="pos",
  122. tikz_options="",
  123. default_node_options="",
  124. node_options="node_options",
  125. node_label="label",
  126. default_edge_options="",
  127. edge_options="edge_options",
  128. edge_label="label",
  129. edge_label_options="edge_label_options",
  130. ):
  131. """Return a string of the LaTeX/TikZ code to draw `G`
  132. This function produces just the code for the tikzpicture
  133. without any enclosing environment.
  134. Parameters
  135. ==========
  136. G : NetworkX graph
  137. The NetworkX graph to be drawn
  138. pos : string or dict (default "pos")
  139. The name of the node attribute on `G` that holds the position of each node.
  140. Positions can be sequences of length 2 with numbers for (x,y) coordinates.
  141. They can also be strings to denote positions in TikZ style, such as (x, y)
  142. or (angle:radius).
  143. If a dict, it should be keyed by node to a position.
  144. If an empty dict, a circular layout is computed by TikZ.
  145. tikz_options : string
  146. The tikzpicture options description defining the options for the picture.
  147. Often large scale options like `[scale=2]`.
  148. default_node_options : string
  149. The draw options for a path of nodes. Individual node options override these.
  150. node_options : string or dict
  151. The name of the node attribute on `G` that holds the options for each node.
  152. Or a dict keyed by node to a string holding the options for that node.
  153. node_label : string or dict
  154. The name of the node attribute on `G` that holds the node label (text)
  155. displayed for each node. If the attribute is "" or not present, the node
  156. itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
  157. Or a dict keyed by node to a string holding the label for that node.
  158. default_edge_options : string
  159. The options for the scope drawing all edges. The default is "[-]" for
  160. undirected graphs and "[->]" for directed graphs.
  161. edge_options : string or dict
  162. The name of the edge attribute on `G` that holds the options for each edge.
  163. If the edge is a self-loop and ``"loop" not in edge_options`` the option
  164. "loop," is added to the options for the self-loop edge. Hence you can
  165. use "[loop above]" explicitly, but the default is "[loop]".
  166. Or a dict keyed by edge to a string holding the options for that edge.
  167. edge_label : string or dict
  168. The name of the edge attribute on `G` that holds the edge label (text)
  169. displayed for each edge. If the attribute is "" or not present, no edge
  170. label is drawn.
  171. Or a dict keyed by edge to a string holding the label for that edge.
  172. edge_label_options : string or dict
  173. The name of the edge attribute on `G` that holds the label options for
  174. each edge. For example, "[sloped,above,blue]". The default is no options.
  175. Or a dict keyed by edge to a string holding the label options for that edge.
  176. Returns
  177. =======
  178. latex_code : string
  179. The text string which draws the desired graph(s) when compiled by LaTeX.
  180. See Also
  181. ========
  182. to_latex
  183. write_latex
  184. """
  185. i4 = "\n "
  186. i8 = "\n "
  187. # set up position dict
  188. # TODO allow pos to be None and use a nice TikZ default
  189. if not isinstance(pos, dict):
  190. pos = nx.get_node_attributes(G, pos)
  191. if not pos:
  192. # circular layout with radius 2
  193. pos = {n: f"({round(360.0 * i / len(G), 3)}:2)" for i, n in enumerate(G)}
  194. for node in G:
  195. if node not in pos:
  196. raise nx.NetworkXError(f"node {node} has no specified pos {pos}")
  197. posnode = pos[node]
  198. if not isinstance(posnode, str):
  199. try:
  200. posx, posy = posnode
  201. pos[node] = f"({round(posx, 3)}, {round(posy, 3)})"
  202. except (TypeError, ValueError):
  203. msg = f"position pos[{node}] is not 2-tuple or a string: {posnode}"
  204. raise nx.NetworkXError(msg)
  205. # set up all the dicts
  206. if not isinstance(node_options, dict):
  207. node_options = nx.get_node_attributes(G, node_options)
  208. if not isinstance(node_label, dict):
  209. node_label = nx.get_node_attributes(G, node_label)
  210. if not isinstance(edge_options, dict):
  211. edge_options = nx.get_edge_attributes(G, edge_options)
  212. if not isinstance(edge_label, dict):
  213. edge_label = nx.get_edge_attributes(G, edge_label)
  214. if not isinstance(edge_label_options, dict):
  215. edge_label_options = nx.get_edge_attributes(G, edge_label_options)
  216. # process default options (add brackets or not)
  217. topts = "" if tikz_options == "" else f"[{tikz_options.strip('[]')}]"
  218. defn = "" if default_node_options == "" else f"[{default_node_options.strip('[]')}]"
  219. linestyle = f"{'->' if G.is_directed() else '-'}"
  220. if default_edge_options == "":
  221. defe = "[" + linestyle + "]"
  222. elif "-" in default_edge_options:
  223. defe = default_edge_options
  224. else:
  225. defe = f"[{linestyle},{default_edge_options.strip('[]')}]"
  226. # Construct the string line by line
  227. result = " \\begin{tikzpicture}" + topts
  228. result += i4 + " \\draw" + defn
  229. # load the nodes
  230. for n in G:
  231. # node options goes inside square brackets
  232. nopts = f"[{node_options[n].strip('[]')}]" if n in node_options else ""
  233. # node text goes inside curly brackets {}
  234. ntext = f"{{{node_label[n]}}}" if n in node_label else f"{{{n}}}"
  235. result += i8 + f"{pos[n]} node{nopts} ({n}){ntext}"
  236. result += ";\n"
  237. # load the edges
  238. result += " \\begin{scope}" + defe
  239. for edge in G.edges:
  240. u, v = edge[:2]
  241. e_opts = f"{edge_options[edge]}".strip("[]") if edge in edge_options else ""
  242. # add loop options for selfloops if not present
  243. if u == v and "loop" not in e_opts:
  244. e_opts = "loop," + e_opts
  245. e_opts = f"[{e_opts}]" if e_opts != "" else ""
  246. # TODO -- handle bending of multiedges
  247. els = edge_label_options[edge] if edge in edge_label_options else ""
  248. # edge label options goes inside square brackets []
  249. els = f"[{els.strip('[]')}]"
  250. # edge text is drawn using the TikZ node command inside curly brackets {}
  251. e_label = f" node{els} {{{edge_label[edge]}}}" if edge in edge_label else ""
  252. result += i8 + f"\\draw{e_opts} ({u}) to{e_label} ({v});"
  253. result += "\n \\end{scope}\n \\end{tikzpicture}\n"
  254. return result
  255. _DOC_WRAPPER_TIKZ = r"""\documentclass{{report}}
  256. \usepackage{{tikz}}
  257. \usepackage{{subcaption}}
  258. \begin{{document}}
  259. {content}
  260. \end{{document}}"""
  261. _FIG_WRAPPER = r"""\begin{{figure}}
  262. {content}{caption}{label}
  263. \end{{figure}}"""
  264. _SUBFIG_WRAPPER = r""" \begin{{subfigure}}{{{size}\textwidth}}
  265. {content}{caption}{label}
  266. \end{{subfigure}}"""
  267. def to_latex(
  268. Gbunch,
  269. pos="pos",
  270. tikz_options="",
  271. default_node_options="",
  272. node_options="node_options",
  273. node_label="node_label",
  274. default_edge_options="",
  275. edge_options="edge_options",
  276. edge_label="edge_label",
  277. edge_label_options="edge_label_options",
  278. caption="",
  279. latex_label="",
  280. sub_captions=None,
  281. sub_labels=None,
  282. n_rows=1,
  283. as_document=True,
  284. document_wrapper=_DOC_WRAPPER_TIKZ,
  285. figure_wrapper=_FIG_WRAPPER,
  286. subfigure_wrapper=_SUBFIG_WRAPPER,
  287. ):
  288. """Return latex code to draw the graph(s) in `Gbunch`
  289. The TikZ drawing utility in LaTeX is used to draw the graph(s).
  290. If `Gbunch` is a graph, it is drawn in a figure environment.
  291. If `Gbunch` is an iterable of graphs, each is drawn in a subfigure environment
  292. within a single figure environment.
  293. If `as_document` is True, the figure is wrapped inside a document environment
  294. so that the resulting string is ready to be compiled by LaTeX. Otherwise,
  295. the string is ready for inclusion in a larger tex document using ``\\include``
  296. or ``\\input`` statements.
  297. Parameters
  298. ==========
  299. Gbunch : NetworkX graph or iterable of NetworkX graphs
  300. The NetworkX graph to be drawn or an iterable of graphs
  301. to be drawn inside subfigures of a single figure.
  302. pos : string or list of strings
  303. The name of the node attribute on `G` that holds the position of each node.
  304. Positions can be sequences of length 2 with numbers for (x,y) coordinates.
  305. They can also be strings to denote positions in TikZ style, such as (x, y)
  306. or (angle:radius).
  307. If a dict, it should be keyed by node to a position.
  308. If an empty dict, a circular layout is computed by TikZ.
  309. If you are drawing many graphs in subfigures, use a list of position dicts.
  310. tikz_options : string
  311. The tikzpicture options description defining the options for the picture.
  312. Often large scale options like `[scale=2]`.
  313. default_node_options : string
  314. The draw options for a path of nodes. Individual node options override these.
  315. node_options : string or dict
  316. The name of the node attribute on `G` that holds the options for each node.
  317. Or a dict keyed by node to a string holding the options for that node.
  318. node_label : string or dict
  319. The name of the node attribute on `G` that holds the node label (text)
  320. displayed for each node. If the attribute is "" or not present, the node
  321. itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
  322. Or a dict keyed by node to a string holding the label for that node.
  323. default_edge_options : string
  324. The options for the scope drawing all edges. The default is "[-]" for
  325. undirected graphs and "[->]" for directed graphs.
  326. edge_options : string or dict
  327. The name of the edge attribute on `G` that holds the options for each edge.
  328. If the edge is a self-loop and ``"loop" not in edge_options`` the option
  329. "loop," is added to the options for the self-loop edge. Hence you can
  330. use "[loop above]" explicitly, but the default is "[loop]".
  331. Or a dict keyed by edge to a string holding the options for that edge.
  332. edge_label : string or dict
  333. The name of the edge attribute on `G` that holds the edge label (text)
  334. displayed for each edge. If the attribute is "" or not present, no edge
  335. label is drawn.
  336. Or a dict keyed by edge to a string holding the label for that edge.
  337. edge_label_options : string or dict
  338. The name of the edge attribute on `G` that holds the label options for
  339. each edge. For example, "[sloped,above,blue]". The default is no options.
  340. Or a dict keyed by edge to a string holding the label options for that edge.
  341. caption : string
  342. The caption string for the figure environment
  343. latex_label : string
  344. The latex label used for the figure for easy referral from the main text
  345. sub_captions : list of strings
  346. The sub_caption string for each subfigure in the figure
  347. sub_latex_labels : list of strings
  348. The latex label for each subfigure in the figure
  349. n_rows : int
  350. The number of rows of subfigures to arrange for multiple graphs
  351. as_document : bool
  352. Whether to wrap the latex code in a document environment for compiling
  353. document_wrapper : formatted text string with variable ``content``.
  354. This text is called to evaluate the content embedded in a document
  355. environment with a preamble setting up TikZ.
  356. figure_wrapper : formatted text string
  357. This text is evaluated with variables ``content``, ``caption`` and ``label``.
  358. It wraps the content and if a caption is provided, adds the latex code for
  359. that caption, and if a label is provided, adds the latex code for a label.
  360. subfigure_wrapper : formatted text string
  361. This text evaluate variables ``size``, ``content``, ``caption`` and ``label``.
  362. It wraps the content and if a caption is provided, adds the latex code for
  363. that caption, and if a label is provided, adds the latex code for a label.
  364. The size is the vertical size of each row of subfigures as a fraction.
  365. Returns
  366. =======
  367. latex_code : string
  368. The text string which draws the desired graph(s) when compiled by LaTeX.
  369. See Also
  370. ========
  371. write_latex
  372. to_latex_raw
  373. """
  374. if hasattr(Gbunch, "adj"):
  375. raw = to_latex_raw(
  376. Gbunch,
  377. pos,
  378. tikz_options,
  379. default_node_options,
  380. node_options,
  381. node_label,
  382. default_edge_options,
  383. edge_options,
  384. edge_label,
  385. edge_label_options,
  386. )
  387. else: # iterator of graphs
  388. sbf = subfigure_wrapper
  389. size = 1 / n_rows
  390. N = len(Gbunch)
  391. if isinstance(pos, (str, dict)):
  392. pos = [pos] * N
  393. if sub_captions is None:
  394. sub_captions = [""] * N
  395. if sub_labels is None:
  396. sub_labels = [""] * N
  397. if not (len(Gbunch) == len(pos) == len(sub_captions) == len(sub_labels)):
  398. raise nx.NetworkXError(
  399. "length of Gbunch, sub_captions and sub_figures must agree"
  400. )
  401. raw = ""
  402. for G, pos, subcap, sublbl in zip(Gbunch, pos, sub_captions, sub_labels):
  403. subraw = to_latex_raw(
  404. G,
  405. pos,
  406. tikz_options,
  407. default_node_options,
  408. node_options,
  409. node_label,
  410. default_edge_options,
  411. edge_options,
  412. edge_label,
  413. edge_label_options,
  414. )
  415. cap = f" \\caption{{{subcap}}}" if subcap else ""
  416. lbl = f"\\label{{{sublbl}}}" if sublbl else ""
  417. raw += sbf.format(size=size, content=subraw, caption=cap, label=lbl)
  418. raw += "\n"
  419. # put raw latex code into a figure environment and optionally into a document
  420. raw = raw[:-1]
  421. cap = f"\n \\caption{{{caption}}}" if caption else ""
  422. lbl = f"\\label{{{latex_label}}}" if latex_label else ""
  423. fig = figure_wrapper.format(content=raw, caption=cap, label=lbl)
  424. if as_document:
  425. return document_wrapper.format(content=fig)
  426. return fig
  427. @nx.utils.open_file(1, mode="w")
  428. def write_latex(Gbunch, path, **options):
  429. """Write the latex code to draw the graph(s) onto `path`.
  430. This convenience function creates the latex drawing code as a string
  431. and writes that to a file ready to be compiled when `as_document` is True
  432. or ready to be ``import`` ed or ``include`` ed into your main LaTeX document.
  433. The `path` argument can be a string filename or a file handle to write to.
  434. Parameters
  435. ----------
  436. Gbunch : NetworkX graph or iterable of NetworkX graphs
  437. If Gbunch is a graph, it is drawn in a figure environment.
  438. If Gbunch is an iterable of graphs, each is drawn in a subfigure
  439. environment within a single figure environment.
  440. path : filename
  441. Filename or file handle to write to
  442. options : dict
  443. By default, TikZ is used with options: (others are ignored)::
  444. pos : string or dict or list
  445. The name of the node attribute on `G` that holds the position of each node.
  446. Positions can be sequences of length 2 with numbers for (x,y) coordinates.
  447. They can also be strings to denote positions in TikZ style, such as (x, y)
  448. or (angle:radius).
  449. If a dict, it should be keyed by node to a position.
  450. If an empty dict, a circular layout is computed by TikZ.
  451. If you are drawing many graphs in subfigures, use a list of position dicts.
  452. tikz_options : string
  453. The tikzpicture options description defining the options for the picture.
  454. Often large scale options like `[scale=2]`.
  455. default_node_options : string
  456. The draw options for a path of nodes. Individual node options override these.
  457. node_options : string or dict
  458. The name of the node attribute on `G` that holds the options for each node.
  459. Or a dict keyed by node to a string holding the options for that node.
  460. node_label : string or dict
  461. The name of the node attribute on `G` that holds the node label (text)
  462. displayed for each node. If the attribute is "" or not present, the node
  463. itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
  464. Or a dict keyed by node to a string holding the label for that node.
  465. default_edge_options : string
  466. The options for the scope drawing all edges. The default is "[-]" for
  467. undirected graphs and "[->]" for directed graphs.
  468. edge_options : string or dict
  469. The name of the edge attribute on `G` that holds the options for each edge.
  470. If the edge is a self-loop and ``"loop" not in edge_options`` the option
  471. "loop," is added to the options for the self-loop edge. Hence you can
  472. use "[loop above]" explicitly, but the default is "[loop]".
  473. Or a dict keyed by edge to a string holding the options for that edge.
  474. edge_label : string or dict
  475. The name of the edge attribute on `G` that holds the edge label (text)
  476. displayed for each edge. If the attribute is "" or not present, no edge
  477. label is drawn.
  478. Or a dict keyed by edge to a string holding the label for that edge.
  479. edge_label_options : string or dict
  480. The name of the edge attribute on `G` that holds the label options for
  481. each edge. For example, "[sloped,above,blue]". The default is no options.
  482. Or a dict keyed by edge to a string holding the label options for that edge.
  483. caption : string
  484. The caption string for the figure environment
  485. latex_label : string
  486. The latex label used for the figure for easy referral from the main text
  487. sub_captions : list of strings
  488. The sub_caption string for each subfigure in the figure
  489. sub_latex_labels : list of strings
  490. The latex label for each subfigure in the figure
  491. n_rows : int
  492. The number of rows of subfigures to arrange for multiple graphs
  493. as_document : bool
  494. Whether to wrap the latex code in a document environment for compiling
  495. document_wrapper : formatted text string with variable ``content``.
  496. This text is called to evaluate the content embedded in a document
  497. environment with a preamble setting up the TikZ syntax.
  498. figure_wrapper : formatted text string
  499. This text is evaluated with variables ``content``, ``caption`` and ``label``.
  500. It wraps the content and if a caption is provided, adds the latex code for
  501. that caption, and if a label is provided, adds the latex code for a label.
  502. subfigure_wrapper : formatted text string
  503. This text evaluate variables ``size``, ``content``, ``caption`` and ``label``.
  504. It wraps the content and if a caption is provided, adds the latex code for
  505. that caption, and if a label is provided, adds the latex code for a label.
  506. The size is the vertical size of each row of subfigures as a fraction.
  507. See Also
  508. ========
  509. to_latex
  510. """
  511. path.write(to_latex(Gbunch, **options))