Example Notebook with Quarto Front Matter

Author

Michael Booth

Published

October 10, 2024

Introduction

This is an example Jupyter notebook that includes Quarto front matter. The front matter is included in a raw cell at the beginning of the notebook.

Code
import pandas as pd
import matplotlib.pyplot as plt
  1. Hide code but show output:
#| echo: false
  1. Show code but hide output:
#| output: false
Code
import numpy as np
random_numbers = np.random.rand(5)
print(random_numbers)
  1. Hide both code and output:
#| include: false
  1. Show code with line numbers:
#| echo: true
#| code-line-numbers: true
Code
def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)

print(fibonacci(10))
55
  1. Fold code (collapsible):
#| code-fold: true
Code
import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
sns.scatterplot(data=tips, x="total_bill", y="tip")
plt.show()

  1. Include warnings in output:
#| warning: true
Code
import warnings
warnings.warn("This is a warning message")
/var/folders/pf/662q3gzd6413np78gpd4p9hr0000gn/T/ipykernel_61213/1498169789.py:2: UserWarning: This is a warning message
  warnings.warn("This is a warning message")
  1. Set figure dimensions:
#| fig-width: 8
#| fig-height: 6
Code
plt.plot([1, 2, 3, 4])
plt.title("Custom Size Plot")
plt.show()

Code
# Create a simple plot

plt.figure(figsize=(10, 6))
plt.plot(df['x'], df['y'], marker='o')
plt.title('Sample Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()

Code
df
x y
0 1 1
1 2 4
2 3 9
3 4 16
4 5 25
5 6 36
6 7 49
7 8 64
8 9 81
9 10 100

Conclusion

This example demonstrates how to include Quarto front matter in a Jupyter notebook. When rendered with Quarto, this notebook will use the specified format options.