Quarto supports executable Python code blocks within markdown. This allows you to create fully reproducible documents and reports—the Python code required to produce your output is part of the document itself, and is automatically re-run whenever the document is rendered.
Code Blocks
Code blocks that use braces around the language name (e.g. {python}) are executable, and will be run by Quarto during render. For a demonstration of a line plot on a polar axis, see Figure 1.
```{python}#| label: fig-polar#| fig-cap: A line plot on a polar axis#| code-fold: falseimport numpy as npimport matplotlib.pyplot as pltr = np.arange(0, 2, 0.01)theta =2* np.pi * rfig, ax = plt.subplots( subplot_kw = {'projection': 'polar'} )ax.plot(theta, r)ax.set_rticks([0.5, 1, 1.5, 2])ax.grid(True)plt.show()```
Figure 1: A line plot on a polar axis
Here is another example:
```{python}import matplotlib.pyplot as pltplt.plot([1,2,3,4])plt.show()```
Inline Code
To include executable expressions within markdown in a Python notebook, you use IPython.display.Markdown to dynamically generate markdown from within an ordinary code cell. For example, if we have a variable radius we can use it within markdown as follow:
```{python}radius =10from IPython.display import display, Markdowndisplay(Markdown("""The radius of the circle is {radius}.""".format(radius = radius)))```