```{python}
#| label: fig-polar
#| fig-cap: A line plot on a polar axis
#| code-fold: false
import numpy as np
import matplotlib.pyplot as plt
= np.arange(0, 2, 0.01)
r = 2 * np.pi * r
theta = plt.subplots(
fig, ax = {'projection': 'polar'}
subplot_kw
)
ax.plot(theta, r)0.5, 1, 1.5, 2])
ax.set_rticks([True)
ax.grid(
plt.show()```
Using Python in Quarto
Execute Python Code in Quarto
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.
Here is another example:
```{python}
import matplotlib.pyplot as plt
1,2,3,4])
plt.plot([
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}
= 10
radius from IPython.display import display, Markdown
"""
display(Markdown(The radius of the circle is {radius}.
""".format(radius = radius)))
```
The radius of the circle is 10.