Skip to content

Commit cc95bbd

Browse files
committed
[ENH] update README.md
1 parent 9c00b48 commit cc95bbd

File tree

1 file changed

+123
-27
lines changed

1 file changed

+123
-27
lines changed

README.md

Lines changed: 123 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,136 @@
11
# Plotting
2-
This is a high-level interface to create publication ready plots using Python with matplotlib and seaborn.
2+
3+
A lightweight, high-level Python library for creating publication-ready scientific figures with consistent styling. Built on top of matplotlib, this package provides a simplified interface for generating plots that meet the standards of scientific journals.
4+
5+
## Features
6+
7+
- **Publication-ready styling**: Clean, professional appearance with proper font embedding
8+
- **Consistent layout**: Standardized spine positioning, grid styling, and tick formatting
9+
- **Flexible units**: Support for both centimeters and inches for figure dimensions
10+
- **Cross-platform**: Works on Linux, macOS, and Windows
11+
- **Minimal dependencies**: Only requires matplotlib
12+
- **Easy customization**: Simple font and size configuration
313

414
## Installation
5-
### Install the package from github
15+
16+
Install directly from GitHub:
17+
618
```bash
7-
pip install git+git@github.com:RDoerfel/plotting.git
19+
pip install git+https://github.com/RDoerfel/plotting.git
820
```
921

10-
## Usage
22+
## Quick Start
23+
1124
```python
1225
from plotting import set_rc_params, get_figures
26+
import numpy as np
1327

14-
28+
# Configure publication-ready styling
1529
set_rc_params(fontfamily="serif", small=8, medium=10, big=12)
16-
fig, axs = get_figures(rows=2, cols=1, unit="cm", figwidth=10, figheight=15, sharex=True, sharey=True)
1730

18-
axs[0].plot([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
31+
# Create figure with subplots
32+
fig, axs = get_figures(rows=2, cols=1, unit="cm", figwidth=10, figheight=15)
33+
34+
# Generate sample data
35+
x = np.linspace(0, 10, 100)
36+
y1 = np.sin(x)
37+
y2 = np.cos(x)
38+
39+
# Plot data
40+
axs[0].plot(x, y1, label='sin(x)')
1941
axs[0].set_xlabel("x")
20-
axs[0].set_ylabel("y")
21-
axs[0].set_xlim(0, 11)
22-
axs[0].set_ylim(0, 11)
23-
axs[0].set_xticks([0, 5, 10])
24-
axs[0].set_yticks([0, 5, 10])
25-
axs[0].set_xticklabels(["0", "5", "10"])
26-
axs[0].set_yticklabels(["0", "5", "10"])
27-
28-
axs[1].plot([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
42+
axs[0].set_ylabel("sin(x)")
43+
axs[0].legend()
44+
45+
axs[1].plot(x, y2, 'r--', label='cos(x)')
2946
axs[1].set_xlabel("x")
30-
axs[1].set_ylabel("y")
31-
axs[1].set_xlim(0, 11)
32-
axs[1].set_ylim(-1, 11)
33-
axs[1].set_xticks([0, 5, 10])
34-
axs[1].set_yticks([0, 5, 10])
35-
axs[1].set_xticklabels(["0", "5", "10"])
36-
axs[1].set_yticklabels(["0", "5", "10"])
37-
38-
fig.tight_layout()
39-
fig.savefig("example_plot.png", dpi=300, bbox_inches="tight", pad_inches=0.1)
40-
```
47+
axs[1].set_ylabel("cos(x)")
48+
axs[1].legend()
49+
50+
# Save with high quality
51+
fig.savefig("scientific_plot.pdf", dpi=300, bbox_inches="tight")
52+
```
53+
54+
## API Reference
55+
56+
### `set_rc_params(fontfamily=None, small=8, medium=10, big=12)`
57+
58+
Configure global matplotlib parameters for publication-ready plots.
59+
60+
**Parameters:**
61+
- `fontfamily` (str, optional): Font family ('serif', 'sans-serif', 'monospace')
62+
- `small` (int): Font size for ticks and legend (default: 8)
63+
- `medium` (int): Font size for labels and default text (default: 10)
64+
- `big` (int): Font size for titles (default: 12)
65+
66+
**Example:**
67+
```python
68+
# Use serif fonts with larger text
69+
set_rc_params(fontfamily="serif", small=10, medium=12, big=14)
70+
```
71+
72+
### `get_figures(rows, cols, unit="cm", figwidth=10, figheight=8, sharex=False, sharey=False, **subplot_kw)`
73+
74+
Create styled figure and axes with publication-ready formatting.
75+
76+
**Parameters:**
77+
- `rows` (int): Number of subplot rows
78+
- `cols` (int): Number of subplot columns
79+
- `unit` (str): Units for dimensions ("cm" or "inch", default: "cm")
80+
- `figwidth` (float): Figure width in specified units (default: 10)
81+
- `figheight` (float): Figure height in specified units (default: 8)
82+
- `sharex` (bool): Share x-axis across subplots (default: False)
83+
- `sharey` (bool): Share y-axis across subplots (default: False)
84+
- `**subplot_kw`: Additional arguments passed to `plt.subplots()`
85+
86+
**Returns:**
87+
- `fig` (matplotlib.figure.Figure): Figure object
88+
- `axs` (matplotlib.axes.Axes or array): Axes object(s)
89+
90+
**Examples:**
91+
```python
92+
# Single plot
93+
fig, ax = get_figures(1, 1, figwidth=8, figheight=6)
94+
95+
# Multiple subplots with shared x-axis
96+
fig, axs = get_figures(3, 2, unit="inch", figwidth=8, figheight=10, sharex=True)
97+
98+
# Custom subplot parameters
99+
fig, axs = get_figures(2, 2, subplot_kw={'facecolor': 'white'})
100+
```
101+
102+
## Styling Features
103+
104+
The library automatically applies several publication-ready styling features:
105+
106+
- **Clean spines**: Removes top and right spines, positions left and bottom spines with appropriate offsets
107+
- **Grid styling**: Adds subtle horizontal grid lines for better readability
108+
- **Tick formatting**: Consistent tick styling with proper direction and sizing
109+
- **Font embedding**: Ensures fonts are properly embedded in PDF outputs (fonttype 42)
110+
- **High DPI**: Default 300 DPI for crisp figures
111+
112+
## Best Practices
113+
114+
1. **Always call `set_rc_params()` first** to ensure consistent styling across all figures
115+
2. **Use centimeters for dimensions** when targeting specific journal requirements
116+
3. **Set explicit axis limits and ticks** for precise control over the appearance
117+
4. **Save as PDF or PNG** with `bbox_inches="tight"` for best quality
118+
119+
## Requirements
120+
121+
- Python ≥ 3.10
122+
- matplotlib ≥ 3.5.0
123+
124+
## License
125+
126+
MIT License - see [LICENSE](LICENSE) file for details.
127+
128+
## Development
129+
130+
This library is designed to be minimal and focused. For testing:
131+
132+
```bash
133+
pytest test/ --cov=plotting
134+
```
135+
136+
The package is tested across Python 3.10, 3.11, and 3.12 on Linux, macOS, and Windows.

0 commit comments

Comments
 (0)