|
| 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°N."), |
| 77 | + ) |
| 78 | + .sub_missing(missing_text="") |
| 79 | +) |
| 80 | +``` |
0 commit comments