Rendering
In [1]:
Copied!
import math
from chalk.core import BaseDiagram
from chalk import *
def help(f):
import pydoc
from IPython.display import HTML
return HTML(pydoc.HTMLDoc().docroutine(f))
import math from chalk.core import BaseDiagram from chalk import * def help(f): import pydoc from IPython.display import HTML return HTML(pydoc.HTMLDoc().docroutine(f))
Chalk supports three back-ends (Cairo, SVG, TikZ), which allow the created Diagram
s to be rendered as PNG, SVG, PDF files, respectively. The three corresponding methods for rendering are: render
, render_svg
, render_pdf
; these are documented below.
Diagram.render¶
In [2]:
Copied!
help(BaseDiagram.render)
help(BaseDiagram.render)
Out[2]:
- render(self: 'Diagram', path: 'str', height: 'int' = 128, width: 'Optional[int]' = None) -> 'None'
- Render the diagram to a PNG file.
Args:
self (Diagram): Given ``Diagram`` instance.
path (str): Path of the .png file.
height (int, optional): Height of the rendered image.
Defaults to 128.
width (Optional[int], optional): Width of the rendered image.
Defaults to None.
In [3]:
Copied!
circle(1).render("circle.png")
from IPython.display import Image
Image("circle.png")
circle(1).render("circle.png") from IPython.display import Image Image("circle.png")
Out[3]:
Diagram.render_svg¶
In [4]:
Copied!
help(BaseDiagram.render_svg)
help(BaseDiagram.render_svg)
Out[4]:
- render(self: 'Diagram', path: 'str', height: 'int' = 128, width: 'Optional[int]' = None, draw_height: 'Optional[int]' = None) -> 'None'
- Render the diagram to an SVG file.
Args:
self (Diagram): Given ``Diagram`` instance.
path (str): Path of the .svg file.
height (int, optional): Height of the rendered image.
Defaults to 128.
width (Optional[int], optional): Width of the rendered image.
Defaults to None.
draw_height (Optional[int], optional): Override the height for
line width.
Diagram.render_pdf¶
In [5]:
Copied!
help(BaseDiagram.render_pdf)
help(BaseDiagram.render_pdf)
Out[5]:
- render(self: 'Diagram', path: 'str', height: 'int' = 128) -> 'None'
Diagram
s in IPython notebooks¶
When a Diagram
is used in an IPython notebook, it is automatically displayed as an SVG. To adjust the height of the generated image, one can use the set_svg_height
function:
In [6]:
Copied!
help(set_svg_height)
help(set_svg_height)
Out[6]:
- set_svg_height(height: 'int') -> 'None'
- Globally set the svg preview height for notebooks.
This function is particularly useful for showing tall drawings:
In [7]:
Copied!
set_svg_height(500)
vcat([circle(1) for _ in range(5)])
set_svg_height(500) vcat([circle(1) for _ in range(5)])
Out[7]:
Last update: 2022-08-22