nx_latex.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 networkx as nx
  111. __all__ = [
  112. "to_latex_raw",
  113. "to_latex",
  114. "write_latex",
  115. ]
  116. @nx.utils.not_implemented_for("multigraph")
  117. def to_latex_raw(
  118. G,
  119. pos="pos",
  120. tikz_options="",
  121. default_node_options="",
  122. node_options="node_options",
  123. node_label="label",
  124. default_edge_options="",
  125. edge_options="edge_options",
  126. edge_label="label",
  127. edge_label_options="edge_label_options",
  128. ):
  129. """Return a string of the LaTeX/TikZ code to draw `G`
  130. This function produces just the code for the tikzpicture
  131. without any enclosing environment.
  132. Parameters
  133. ==========
  134. G : NetworkX graph
  135. The NetworkX graph to be drawn
  136. pos : string or dict (default "pos")
  137. The name of the node attribute on `G` that holds the position of each node.
  138. Positions can be sequences of length 2 with numbers for (x,y) coordinates.
  139. They can also be strings to denote positions in TikZ style, such as (x, y)
  140. or (angle:radius).
  141. If a dict, it should be keyed by node to a position.
  142. If an empty dict, a circular layout is computed by TikZ.
  143. tikz_options : string
  144. The tikzpicture options description defining the options for the picture.
  145. Often large scale options like `[scale=2]`.
  146. default_node_options : string
  147. The draw options for a path of nodes. Individual node options override these.
  148. node_options : string or dict
  149. The name of the node attribute on `G` that holds the options for each node.
  150. Or a dict keyed by node to a string holding the options for that node.
  151. node_label : string or dict
  152. The name of the node attribute on `G` that holds the node label (text)
  153. displayed for each node. If the attribute is "" or not present, the node
  154. itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
  155. Or a dict keyed by node to a string holding the label for that node.
  156. default_edge_options : string
  157. The options for the scope drawing all edges. The default is "[-]" for
  158. undirected graphs and "[->]" for directed graphs.
  159. edge_options : string or dict
  160. The name of the edge attribute on `G` that holds the options for each edge.
  161. If the edge is a self-loop and ``"loop" not in edge_options`` the option
  162. "loop," is added to the options for the self-loop edge. Hence you can
  163. use "[loop above]" explicitly, but the default is "[loop]".
  164. Or a dict keyed by edge to a string holding the options for that edge.
  165. edge_label : string or dict
  166. The name of the edge attribute on `G` that holds the edge label (text)
  167. displayed for each edge. If the attribute is "" or not present, no edge
  168. label is drawn.
  169. Or a dict keyed by edge to a string holding the label for that edge.
  170. edge_label_options : string or dict
  171. The name of the edge attribute on `G` that holds the label options for
  172. each edge. For example, "[sloped,above,blue]". The default is no options.
  173. Or a dict keyed by edge to a string holding the label options for that edge.
  174. Returns
  175. =======
  176. latex_code : string
  177. The text string which draws the desired graph(s) when compiled by LaTeX.
  178. See Also
  179. ========
  180. to_latex
  181. write_latex
  182. """
  183. i4 = "\n "
  184. i8 = "\n "
  185. # set up position dict
  186. # TODO allow pos to be None and use a nice TikZ default
  187. if not isinstance(pos, dict):
  188. pos = nx.get_node_attributes(G, pos)
  189. if not pos:
  190. # circular layout with radius 2
  191. pos = {n: f"({round(360.0 * i / len(G), 3)}:2)" for i, n in enumerate(G)}
  192. for node in G:
  193. if node not in pos:
  194. raise nx.NetworkXError(f"node {node} has no specified pos {pos}")
  195. posnode = pos[node]
  196. if not isinstance(posnode, str):
  197. try:
  198. posx, posy = posnode
  199. pos[node] = f"({round(posx, 3)}, {round(posy, 3)})"
  200. except (TypeError, ValueError):
  201. msg = f"position pos[{node}] is not 2-tuple or a string: {posnode}"
  202. raise nx.NetworkXError(msg)
  203. # set up all the dicts
  204. if not isinstance(node_options, dict):
  205. node_options = nx.get_node_attributes(G, node_options)
  206. if not isinstance(node_label, dict):
  207. node_label = nx.get_node_attributes(G, node_label)
  208. if not isinstance(edge_options, dict):
  209. edge_options = nx.get_edge_attributes(G, edge_options)
  210. if not isinstance(edge_label, dict):
  211. edge_label = nx.get_edge_attributes(G, edge_label)
  212. if not isinstance(edge_label_options, dict):
  213. edge_label_options = nx.get_edge_attributes(G, edge_label_options)
  214. # process default options (add brackets or not)
  215. topts = "" if tikz_options == "" else f"[{tikz_options.strip('[]')}]"
  216. defn = "" if default_node_options == "" else f"[{default_node_options.strip('[]')}]"
  217. linestyle = f"{'->' if G.is_directed() else '-'}"
  218. if default_edge_options == "":
  219. defe = "[" + linestyle + "]"
  220. elif "-" in default_edge_options:
  221. defe = default_edge_options
  222. else:
  223. defe = f"[{linestyle},{default_edge_options.strip('[]')}]"
  224. # Construct the string line by line
  225. result = " \\begin{tikzpicture}" + topts
  226. result += i4 + " \\draw" + defn
  227. # load the nodes
  228. for n in G:
  229. # node options goes inside square brackets
  230. nopts = f"[{node_options[n].strip('[]')}]" if n in node_options else ""
  231. # node text goes inside curly brackets {}
  232. ntext = f"{{{node_label[n]}}}" if n in node_label else f"{{{n}}}"
  233. result += i8 + f"{pos[n]} node{nopts} ({n}){ntext}"
  234. result += ";\n"
  235. # load the edges
  236. result += " \\begin{scope}" + defe
  237. for edge in G.edges:
  238. u, v = edge[:2]
  239. e_opts = f"{edge_options[edge]}".strip("[]") if edge in edge_options else ""
  240. # add loop options for selfloops if not present
  241. if u == v and "loop" not in e_opts:
  242. e_opts = "loop," + e_opts
  243. e_opts = f"[{e_opts}]" if e_opts != "" else ""
  244. # TODO -- handle bending of multiedges
  245. els = edge_label_options[edge] if edge in edge_label_options else ""
  246. # edge label options goes inside square brackets []
  247. els = f"[{els.strip('[]')}]"
  248. # edge text is drawn using the TikZ node command inside curly brackets {}
  249. e_label = f" node{els} {{{edge_label[edge]}}}" if edge in edge_label else ""
  250. result += i8 + f"\\draw{e_opts} ({u}) to{e_label} ({v});"
  251. result += "\n \\end{scope}\n \\end{tikzpicture}\n"
  252. return result
  253. _DOC_WRAPPER_TIKZ = r"""\documentclass{{report}}
  254. \usepackage{{tikz}}
  255. \usepackage{{subcaption}}
  256. \begin{{document}}
  257. {content}
  258. \end{{document}}"""
  259. _FIG_WRAPPER = r"""\begin{{figure}}
  260. {content}{caption}{label}
  261. \end{{figure}}"""
  262. _SUBFIG_WRAPPER = r""" \begin{{subfigure}}{{{size}\textwidth}}
  263. {content}{caption}{label}
  264. \end{{subfigure}}"""
  265. def to_latex(
  266. Gbunch,
  267. pos="pos",
  268. tikz_options="",
  269. default_node_options="",
  270. node_options="node_options",
  271. node_label="node_label",
  272. default_edge_options="",
  273. edge_options="edge_options",
  274. edge_label="edge_label",
  275. edge_label_options="edge_label_options",
  276. caption="",
  277. latex_label="",
  278. sub_captions=None,
  279. sub_labels=None,
  280. n_rows=1,
  281. as_document=True,
  282. document_wrapper=_DOC_WRAPPER_TIKZ,
  283. figure_wrapper=_FIG_WRAPPER,
  284. subfigure_wrapper=_SUBFIG_WRAPPER,
  285. ):
  286. """Return latex code to draw the graph(s) in `Gbunch`
  287. The TikZ drawing utility in LaTeX is used to draw the graph(s).
  288. If `Gbunch` is a graph, it is drawn in a figure environment.
  289. If `Gbunch` is an iterable of graphs, each is drawn in a subfigure environment
  290. within a single figure environment.
  291. If `as_document` is True, the figure is wrapped inside a document environment
  292. so that the resulting string is ready to be compiled by LaTeX. Otherwise,
  293. the string is ready for inclusion in a larger tex document using ``\\include``
  294. or ``\\input`` statements.
  295. Parameters
  296. ==========
  297. Gbunch : NetworkX graph or iterable of NetworkX graphs
  298. The NetworkX graph to be drawn or an iterable of graphs
  299. to be drawn inside subfigures of a single figure.
  300. pos : string or list of strings
  301. The name of the node attribute on `G` that holds the position of each node.
  302. Positions can be sequences of length 2 with numbers for (x,y) coordinates.
  303. They can also be strings to denote positions in TikZ style, such as (x, y)
  304. or (angle:radius).
  305. If a dict, it should be keyed by node to a position.
  306. If an empty dict, a circular layout is computed by TikZ.
  307. If you are drawing many graphs in subfigures, use a list of position dicts.
  308. tikz_options : string
  309. The tikzpicture options description defining the options for the picture.
  310. Often large scale options like `[scale=2]`.
  311. default_node_options : string
  312. The draw options for a path of nodes. Individual node options override these.
  313. node_options : string or dict
  314. The name of the node attribute on `G` that holds the options for each node.
  315. Or a dict keyed by node to a string holding the options for that node.
  316. node_label : string or dict
  317. The name of the node attribute on `G` that holds the node label (text)
  318. displayed for each node. If the attribute is "" or not present, the node
  319. itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
  320. Or a dict keyed by node to a string holding the label for that node.
  321. default_edge_options : string
  322. The options for the scope drawing all edges. The default is "[-]" for
  323. undirected graphs and "[->]" for directed graphs.
  324. edge_options : string or dict
  325. The name of the edge attribute on `G` that holds the options for each edge.
  326. If the edge is a self-loop and ``"loop" not in edge_options`` the option
  327. "loop," is added to the options for the self-loop edge. Hence you can
  328. use "[loop above]" explicitly, but the default is "[loop]".
  329. Or a dict keyed by edge to a string holding the options for that edge.
  330. edge_label : string or dict
  331. The name of the edge attribute on `G` that holds the edge label (text)
  332. displayed for each edge. If the attribute is "" or not present, no edge
  333. label is drawn.
  334. Or a dict keyed by edge to a string holding the label for that edge.
  335. edge_label_options : string or dict
  336. The name of the edge attribute on `G` that holds the label options for
  337. each edge. For example, "[sloped,above,blue]". The default is no options.
  338. Or a dict keyed by edge to a string holding the label options for that edge.
  339. caption : string
  340. The caption string for the figure environment
  341. latex_label : string
  342. The latex label used for the figure for easy referral from the main text
  343. sub_captions : list of strings
  344. The sub_caption string for each subfigure in the figure
  345. sub_latex_labels : list of strings
  346. The latex label for each subfigure in the figure
  347. n_rows : int
  348. The number of rows of subfigures to arrange for multiple graphs
  349. as_document : bool
  350. Whether to wrap the latex code in a document environment for compiling
  351. document_wrapper : formatted text string with variable ``content``.
  352. This text is called to evaluate the content embedded in a document
  353. environment with a preamble setting up TikZ.
  354. figure_wrapper : formatted text string
  355. This text is evaluated with variables ``content``, ``caption`` and ``label``.
  356. It wraps the content and if a caption is provided, adds the latex code for
  357. that caption, and if a label is provided, adds the latex code for a label.
  358. subfigure_wrapper : formatted text string
  359. This text evaluate variables ``size``, ``content``, ``caption`` and ``label``.
  360. It wraps the content and if a caption is provided, adds the latex code for
  361. that caption, and if a label is provided, adds the latex code for a label.
  362. The size is the vertical size of each row of subfigures as a fraction.
  363. Returns
  364. =======
  365. latex_code : string
  366. The text string which draws the desired graph(s) when compiled by LaTeX.
  367. See Also
  368. ========
  369. write_latex
  370. to_latex_raw
  371. """
  372. if hasattr(Gbunch, "adj"):
  373. raw = to_latex_raw(
  374. Gbunch,
  375. pos,
  376. tikz_options,
  377. default_node_options,
  378. node_options,
  379. node_label,
  380. default_edge_options,
  381. edge_options,
  382. edge_label,
  383. edge_label_options,
  384. )
  385. else: # iterator of graphs
  386. sbf = subfigure_wrapper
  387. size = 1 / n_rows
  388. N = len(Gbunch)
  389. if isinstance(pos, str | dict):
  390. pos = [pos] * N
  391. if sub_captions is None:
  392. sub_captions = [""] * N
  393. if sub_labels is None:
  394. sub_labels = [""] * N
  395. if not (len(Gbunch) == len(pos) == len(sub_captions) == len(sub_labels)):
  396. raise nx.NetworkXError(
  397. "length of Gbunch, sub_captions and sub_figures must agree"
  398. )
  399. raw = ""
  400. for G, pos, subcap, sublbl in zip(Gbunch, pos, sub_captions, sub_labels):
  401. subraw = to_latex_raw(
  402. G,
  403. pos,
  404. tikz_options,
  405. default_node_options,
  406. node_options,
  407. node_label,
  408. default_edge_options,
  409. edge_options,
  410. edge_label,
  411. edge_label_options,
  412. )
  413. cap = f" \\caption{{{subcap}}}" if subcap else ""
  414. lbl = f"\\label{{{sublbl}}}" if sublbl else ""
  415. raw += sbf.format(size=size, content=subraw, caption=cap, label=lbl)
  416. raw += "\n"
  417. # put raw latex code into a figure environment and optionally into a document
  418. raw = raw[:-1]
  419. cap = f"\n \\caption{{{caption}}}" if caption else ""
  420. lbl = f"\\label{{{latex_label}}}" if latex_label else ""
  421. fig = figure_wrapper.format(content=raw, caption=cap, label=lbl)
  422. if as_document:
  423. return document_wrapper.format(content=fig)
  424. return fig
  425. @nx.utils.open_file(1, mode="w")
  426. def write_latex(Gbunch, path, **options):
  427. """Write the latex code to draw the graph(s) onto `path`.
  428. This convenience function creates the latex drawing code as a string
  429. and writes that to a file ready to be compiled when `as_document` is True
  430. or ready to be ``import`` ed or ``include`` ed into your main LaTeX document.
  431. The `path` argument can be a string filename or a file handle to write to.
  432. Parameters
  433. ----------
  434. Gbunch : NetworkX graph or iterable of NetworkX graphs
  435. If Gbunch is a graph, it is drawn in a figure environment.
  436. If Gbunch is an iterable of graphs, each is drawn in a subfigure
  437. environment within a single figure environment.
  438. path : string or file
  439. Filename or file handle to write to.
  440. Filenames ending in .gz or .bz2 will be compressed.
  441. options : dict
  442. By default, TikZ is used with options: (others are ignored)::
  443. pos : string or dict or list
  444. The name of the node attribute on `G` that holds the position of each node.
  445. Positions can be sequences of length 2 with numbers for (x,y) coordinates.
  446. They can also be strings to denote positions in TikZ style, such as (x, y)
  447. or (angle:radius).
  448. If a dict, it should be keyed by node to a position.
  449. If an empty dict, a circular layout is computed by TikZ.
  450. If you are drawing many graphs in subfigures, use a list of position dicts.
  451. tikz_options : string
  452. The tikzpicture options description defining the options for the picture.
  453. Often large scale options like `[scale=2]`.
  454. default_node_options : string
  455. The draw options for a path of nodes. Individual node options override these.
  456. node_options : string or dict
  457. The name of the node attribute on `G` that holds the options for each node.
  458. Or a dict keyed by node to a string holding the options for that node.
  459. node_label : string or dict
  460. The name of the node attribute on `G` that holds the node label (text)
  461. displayed for each node. If the attribute is "" or not present, the node
  462. itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
  463. Or a dict keyed by node to a string holding the label for that node.
  464. default_edge_options : string
  465. The options for the scope drawing all edges. The default is "[-]" for
  466. undirected graphs and "[->]" for directed graphs.
  467. edge_options : string or dict
  468. The name of the edge attribute on `G` that holds the options for each edge.
  469. If the edge is a self-loop and ``"loop" not in edge_options`` the option
  470. "loop," is added to the options for the self-loop edge. Hence you can
  471. use "[loop above]" explicitly, but the default is "[loop]".
  472. Or a dict keyed by edge to a string holding the options for that edge.
  473. edge_label : string or dict
  474. The name of the edge attribute on `G` that holds the edge label (text)
  475. displayed for each edge. If the attribute is "" or not present, no edge
  476. label is drawn.
  477. Or a dict keyed by edge to a string holding the label for that edge.
  478. edge_label_options : string or dict
  479. The name of the edge attribute on `G` that holds the label options for
  480. each edge. For example, "[sloped,above,blue]". The default is no options.
  481. Or a dict keyed by edge to a string holding the label options for that edge.
  482. caption : string
  483. The caption string for the figure environment
  484. latex_label : string
  485. The latex label used for the figure for easy referral from the main text
  486. sub_captions : list of strings
  487. The sub_caption string for each subfigure in the figure
  488. sub_latex_labels : list of strings
  489. The latex label for each subfigure in the figure
  490. n_rows : int
  491. The number of rows of subfigures to arrange for multiple graphs
  492. as_document : bool
  493. Whether to wrap the latex code in a document environment for compiling
  494. document_wrapper : formatted text string with variable ``content``.
  495. This text is called to evaluate the content embedded in a document
  496. environment with a preamble setting up the TikZ syntax.
  497. figure_wrapper : formatted text string
  498. This text is evaluated with variables ``content``, ``caption`` and ``label``.
  499. It wraps the content and if a caption is provided, adds the latex code for
  500. that caption, and if a label is provided, adds the latex code for a label.
  501. subfigure_wrapper : formatted text string
  502. This text evaluate variables ``size``, ``content``, ``caption`` and ``label``.
  503. It wraps the content and if a caption is provided, adds the latex code for
  504. that caption, and if a label is provided, adds the latex code for a label.
  505. The size is the vertical size of each row of subfigures as a fraction.
  506. See Also
  507. ========
  508. to_latex
  509. """
  510. path.write(to_latex(Gbunch, **options))