Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

docs: mpl.interactive (#160)

Akshay Agrawalf97ff514a9b6
diff --git a/docs/api/index.md b/docs/api/index.md
index 332bd2de19..d18751e042 100644
--- a/docs/api/index.md
+++ b/docs/api/index.md
@@ -8,6 +8,7 @@
markdown
inputs/index
layouts/index
+ plotting
media/index
html
control_flow
@@ -26,6 +27,7 @@ and more.
| {doc}`markdown` | Write markdown with `mo.md` |
| {doc}`inputs/index` | Connect sliders, dropdowns, tables, and more to Python |
| {doc}`layouts/index` | Customize outputs with accordions, tabs, stacks, and more |
+| {doc}`plotting` | Output interactive plots |
| {doc}`media/index` | Output media like images, audio, and PDFs |
| {doc}`html` | Manipulate HTML objects |
| {doc}`control_flow` | Control how cells execute |
diff --git a/docs/api/plotting.md b/docs/api/plotting.md
new file mode 100644
index 0000000000..48b1e6f751
--- /dev/null
+++ b/docs/api/plotting.md
@@ -0,0 +1,38 @@
+# Plotting
+
+marimo supports all major plotting libraries, including matplotlib, seaborn,
+plotly, and altair. Just import your plotting library of choice and use it
+as you normally would.
+
+```{admonition} Reactive plots coming soon!
+:class: admonition
+
+We're working on a way to let you select data in a plot with your mouse, and
+have your selection automatically passed to Python — stay tuned!
+```
+
+**Tip: outputting matplotlib plots.**
+To output a matplotlib plot in a cell's output area, include its `Axes` or
+`Figure` object as the last expression in your notebook. For example:
+
+```python
+plt.plot([1, 2])
+# plt.gca() gets the current `Axes`
+plt.gca()
+```
+
+or
+
+```python
+fig, ax = plt.subplots()
+
+ax.plot([1, 2])
+ax
+```
+
+If you want to output the plot in the console area, use `plt.show()` or
+`fig.show()`.
+
+```{eval-rst}
+.. autofunction:: marimo.mpl.interactive
+```
diff --git a/docs/faq.md b/docs/faq.md
index 7fe86b2a9c..cb92a86c32 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -10,6 +10,7 @@
- [How do I add a submit button to UI elements?](#faq-form)
- [How do I write markdown?](#faq-markdown)
- [How do I display plots?](#faq-plots)
+ - [How do I display interactive matplotlib plots?](#faq-interactive-plots)
- [How do I display objects in rows and columns?](#faq-rows-columns)
- [What packages can I use?](#faq-packages)
- [What's the difference between a marimo notebook and a marimo app?](#faq-notebook-app)
@@ -133,6 +134,19 @@ other outputs. If you're using matplotlib, you can display the `Figure` object
marimo tutorial plots
```
+Also see the <a href="/api/plotting.html">plotting API reference</a>.
+
+<a name="faq-interactive-plots" ></a>
+**How do I display interactive matplotlib plots?**
+
+Use <a href="/api/plotting.html#marimo.mpl.interactive">`marimo.mpl.interactive`</a>.
+
+```bash
+fig, ax = plt.subplots()
+ax.plot([1, 2])
+mo.mpl.interactive(ax)
+```
+
<a name="faq-rows-columns" ></a>
**How do I display objects in rows and columns?**
diff --git a/docs/index.md b/docs/index.md
index 1da39e476b..641a810acf 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -8,7 +8,7 @@ that double as apps**. marimo is:
- **reactive**: run a cell and marimo automatically runs cells that depend on it
- **interactive**: interact with sliders, tables, and more to run cells
- **reproducible**: no hidden state
-- **simple**: no complicated callbacks, no magical syntax
+- **simple**: no callbacks, no magical syntax
- **expressive**: parametrize markdown with interactive elements, plots, or anything else
- **Pythonic**: cells only run Python; notebooks stored as `.py` files (clean git diffs!)
- **performant**: powered by static analysis, zero runtime overhead