File size: 2,751 Bytes
1c14d3f
6776d0e
 
 
 
 
 
 
 
1c14d3f
6776d0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
pretty_name: Matplotlib Code-Image Pairs
license: other
tags:
- matplotlib
- code
- plotting
- computer-vision
- synthetic
---

# Matplotlib Code-Image Pairs

## Dataset Summary

This dataset contains static Matplotlib figure images paired with the Python source code that generated them.
It was built from the official Matplotlib gallery and excludes animation-style examples.
Each row corresponds to one rendered image. Examples that produce multiple figures contribute multiple rows.

## Dataset Composition

- Image/code rows: 643
- Source examples: 452
- Examples with multiple figures: 74
- Included statuses: ok
- Source gallery: https://matplotlib.org/stable/gallery/index.html

## Top Categories

- `lines_bars_and_markers`: 48 examples
- `images_contours_and_fields`: 47 examples
- `text_labels_and_annotations`: 46 examples
- `mplot3d`: 44 examples
- `subplots_axes_and_figures`: 35 examples
- `misc`: 25 examples
- `ticks`: 24 examples
- `axes_grid1`: 22 examples
- `statistics`: 21 examples
- `event_handling`: 20 examples

## Row Schema

- `image`: rendered PNG for one figure
- `code`: full Python source for the example
- `example_id`: stable identifier derived from the Matplotlib gallery URL
- `figure_index`: zero-based figure index within the example
- `figure_name`: original rendered image filename
- `title`: example page title
- `example_page_url`: Matplotlib gallery page URL
- `source_url`: downloadable Python source URL when available
- `source_relpath`: source filename reported by the scraper
- `category_hint`: rough gallery category inferred from the URL path
- `status`: scraper/render status kept for provenance
- `num_figures`: number of figures reported for the source example
- `error`: render or scrape error text, usually null for successful rows

## Build Process

1. Crawl the official Matplotlib gallery.
2. Download the Python source for each example page.
3. Render examples with Matplotlib's non-interactive `Agg` backend.
4. Keep static rendered image/code pairs and skip dynamic animation-style examples.
5. Export one dataset row per rendered image.

## Usage

Load the local saved dataset:

```python
from datasets import load_from_disk

ds = load_from_disk("/usr/project/xtmp/ap843/hf_datasets/matplotlib_code_image_pairs")["train"]
```

Load from the Hugging Face Hub after pushing:

```python
from datasets import load_dataset

ds = load_dataset("ajayvikram/matplotlib-code-image", split="train")
```

## License And Attribution

This dataset is derived from Matplotlib gallery examples. The dataset card uses `license: other` by default,
but you should verify the correct redistribution requirements before publishing publicly and retain appropriate
Matplotlib attribution and license notices.