Skip to content

Commit 46299db

Browse files
committed
feat: enhance documentation with new examples and images for Matplotlib sizing
1 parent 91ea5ec commit 46299db

File tree

7 files changed

+52
-5
lines changed

7 files changed

+52
-5
lines changed

docs/api.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
This section is rendered from the package's type hints and NumPy-style docstrings using [`mkdocstrings`](https://mkdocstrings.github.io/). Update the inline documentation in `src/physics_plot/` and rebuild the docs to refresh the content.
44

5-
## Legend Containers
5+
::: physics_plot
66

7-
::: physics_plot.utils.Handles

docs/examples.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
See the [examples directory on GitHub](https://github.com/c0rychu/physics-plot/tree/main/examples).
44

5+
6+
```python title="examples/bode-plot.py"
7+
--8<-- "examples/bode-plot.py"
8+
```
9+
![Bode plot example](https://raw.githubusercontent.com/c0rychu/physics-plot/main/examples/bode-plot%402x.png)
10+
511
<!-- Physics Plot ships with runnable demos so you can see how the style sheet and utilities behave on real data. Clone the repository locally, install the dependencies, and run the scripts from the project root.
612
713
## Bode Plot

docs/mpl/mpl-size-lg.png

294 KB
Loading

docs/mpl/mpl-size-sm.png

95.3 KB
Loading

docs/mpl/mpl-size.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The first and the most important trick when plotting with Matplotlib is to set the figure size appropriately.
2+
If you want to increase the font size and line width everywhere in the figure, the easiest way is to **decrease the figure size**!
3+
4+
!!! tip
5+
This is counter-intuitive at first, but it works because Matplotlib scales text elements (like axis labels, tick labels, legends, etc.) relative to the figure size.
6+
So a smaller figure size results in larger text elements, making them more readable.
7+
8+
9+
```python
10+
--8<-- "mpl/mpl-size.py"
11+
```
12+
13+
![small size](mpl-size-sm.png)
14+
![large size](mpl-size-lg.png)

docs/mpl/mpl-size.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
plt.style.use("physics_plot.pp_base")
5+
6+
fig, ax = plt.subplots(figsize=(4, 2), constrained_layout=True)
7+
x = np.linspace(0, 10, 100)
8+
y = np.sin(x)
9+
ax.plot(x, y, label="Sine Wave")
10+
ax.set_ylabel(r"$y(x)$")
11+
ax.set_xlabel(r"$x$")
12+
ax.legend(loc="upper right")
13+
fig.suptitle(r"\texttt{figsize=(4, 2)}")
14+
fig.savefig("mpl-size-sm.png")
15+
16+
17+
fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)
18+
x = np.linspace(0, 10, 100)
19+
y = np.sin(x)
20+
ax.plot(x, y, label="Sine Wave")
21+
ax.set_ylabel(r"$y(x)$")
22+
ax.set_xlabel(r"$x$")
23+
ax.legend(loc="upper right")
24+
fig.suptitle(r"\texttt{figsize=(10, 5)}")
25+
fig.savefig("mpl-size-lg.png")

mkdocs.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ markdown_extensions:
4747
- pymdownx.details
4848
- pymdownx.highlight
4949
- pymdownx.inlinehilite
50-
- pymdownx.snippets
50+
- pymdownx.snippets:
51+
base_path: [docs, .]
5152
- pymdownx.superfences
5253
plugins:
53-
- search
5454
- mkdocstrings:
5555
handlers:
5656
python:
57+
paths: [src]
5758
options:
58-
docstring_style: numpy
59+
show_root_heading: true
60+
show_submodules: true
5961
show_source: true
62+
docstring_style: numpy
6063
members_order: alphabetical
6164
extra:
6265
social:

0 commit comments

Comments
 (0)