Skip to content

Commit a6c1e4b

Browse files
committed
Add a notebook example
1 parent 26899dd commit a6c1e4b

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

_quarto.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
project:
22
type: website
3-
render:
3+
render: # Add HERE new chapters and new notebooks
44
- index.qmd
55
- chapters/chapter1.qmd
6+
- notebooks/notebook1.qmd
67

78
website:
89
page-navigation: true
@@ -12,7 +13,7 @@ website:
1213
repo-actions: [edit, source, issue]
1314
sidebar:
1415
search: true
15-
contents:
16+
contents: # Add HERE new chapters
1617
- href: index.qmd
1718
text: Introduction
1819
- href: chapters/chapter1.qmd

chapters/chapter1.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "A basic notebook"
3-
format: [html, ipynb] # This qmd file will be compiled as HTML and as a jupyter notebook
2+
title: "A basic chapter"
3+
format: html # This qmd file will be compiled as an HTML web page
44
---
55

66
# A beautiful figure
@@ -25,7 +25,7 @@ ax.grid(True)
2525
plt.show()
2626
```
2727

28-
## A beautiful datafrmae
28+
## A beautiful dataframe
2929

3030
This section demonstrates how to create and display a simple pandas DataFrame.
3131

notebooks/notebook1.qmd

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: "A basic notebook"
3+
format: ipynb # This qmd file will be compiled as a jupyter notebook
4+
---
5+
6+
# A beautiful figure
7+
8+
This chunk shows how you can produce a beautiful figure.
9+
10+
```{python}
11+
#| label: fig-polar
12+
#| fig-cap: "A line plot on a polar axis"
13+
14+
import numpy as np
15+
import matplotlib.pyplot as plt
16+
17+
r = np.arange(0, 2, 0.01)
18+
theta = 2 * np.pi * r
19+
fig, ax = plt.subplots(
20+
subplot_kw = {'projection': 'polar'}
21+
)
22+
ax.plot(theta, r)
23+
ax.set_rticks([0.5, 1, 1.5, 2])
24+
ax.grid(True)
25+
plt.show()
26+
```
27+
28+
## A beautiful dataframe
29+
30+
This section demonstrates how to create and display a simple pandas DataFrame.
31+
32+
```{python}
33+
#| label: tbl-pandas
34+
#| tbl-cap: "Simple pandas DataFrame"
35+
36+
import pandas as pd
37+
38+
data = {
39+
"Name": ["Alice", "Bob", "Charlie"],
40+
"Age": [25, 30, 35],
41+
"City": ["Paris", "Dublin", "Berlin"]
42+
}
43+
44+
df = pd.DataFrame(data)
45+
df
46+
```
47+
48+
## A more sophisticated table
49+
50+
This section demonstrates how to create and display a simple pandas DataFrame.
51+
52+
```{python}
53+
from great_tables import GT, html
54+
from great_tables.data import sza
55+
import polars as pl
56+
from polars import col as c
57+
import polars.selectors as cs
58+
59+
sza_pivot = (
60+
pl.from_pandas(sza)
61+
.filter((c.latitude == "20") & (c.tst <= "1200"))
62+
.select(pl.col("*").exclude("latitude"))
63+
.drop_nulls()
64+
.pivot(values="sza", index="month", on="tst", sort_columns=True)
65+
)
66+
67+
(
68+
GT(sza_pivot, rowname_col="month")
69+
.data_color(
70+
domain=[90, 0],
71+
palette=["rebeccapurple", "white", "orange"],
72+
na_color="white",
73+
)
74+
.tab_header(
75+
title="Solar Zenith Angles from 05:30 to 12:00",
76+
subtitle=html("Average monthly values at latitude of 20&deg;N."),
77+
)
78+
.sub_missing(missing_text="")
79+
)
80+
```

0 commit comments

Comments
 (0)