Skip to content

Commit 1b8b603

Browse files
Add README
1 parent 860abd2 commit 1b8b603

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ venv/
22
.idea
33
__pycache__
44
result_images
5+
.pytest_cache

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# matplotview
2+
#### A library for creating lightweight views of matplotlib axes.
3+
4+
matplotview provides a simple interface for creating "views" of matplotlib
5+
axes, providing a simple way of displaying overviews and zoomed views of
6+
data without plotting data twice.
7+
8+
## Examples
9+
10+
An example of two axes showing the same plot.
11+
```python
12+
from matplotview import view
13+
import matplotlib.pyplot as plt
14+
import numpy as np
15+
16+
fig, (ax1, ax2) = plt.subplots(1, 2)
17+
18+
# Plot a line, circle patch, some text, and an image...
19+
ax1.plot([i for i in range(10)], "r")
20+
ax1.add_patch(plt.Circle((3, 3), 1, ec="black", fc="blue"))
21+
ax1.text(10, 10, "Hello World!", size=20)
22+
ax1.imshow(np.random.rand(30, 30), origin="lower", cmap="Blues", alpha=0.5,
23+
interpolation="nearest")
24+
25+
# Turn axes 2 into a view of axes 1.
26+
view(ax2, ax1)
27+
# Modify the second axes data limits to match the first axes...
28+
ax2.set_aspect(ax1.get_aspect())
29+
ax2.set_xlim(ax1.get_xlim())
30+
ax2.set_ylim(ax1.get_ylim())
31+
32+
fig.tight_layout()
33+
fig.show()
34+
```
35+
![First example plot results, two views of the same plot.](_images/example1.png)
36+
37+
An inset zoom example.
38+
```python
39+
from matplotlib import cbook
40+
import matplotlib.pyplot as plt
41+
import numpy as np
42+
from matplotview import inset_zoom_axes
43+
44+
def get_demo_image():
45+
z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
46+
# z is a numpy array of 15x15
47+
return z, (-3, 4, -4, 3)
48+
49+
fig, ax = plt.subplots(figsize=[5, 4])
50+
51+
# Make the data...
52+
Z, extent = get_demo_image()
53+
Z2 = np.zeros((150, 150))
54+
ny, nx = Z.shape
55+
Z2[30:30+ny, 30:30+nx] = Z
56+
57+
ax.imshow(Z2, extent=extent, interpolation='nearest', origin="lower")
58+
59+
# Creates an inset axes with automatic view of the parent axes...
60+
axins = inset_zoom_axes(ax, [0.5, 0.5, 0.47, 0.47])
61+
# Set limits to sub region of the original image
62+
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
63+
axins.set_xlim(x1, x2)
64+
axins.set_ylim(y1, y2)
65+
axins.set_xticklabels([])
66+
axins.set_yticklabels([])
67+
68+
ax.indicate_inset_zoom(axins, edgecolor="black")
69+
70+
fig.show()
71+
```
72+
![Second example plot results, an inset axes showing a zoom view of an image.](_images/example2.png)

0 commit comments

Comments
 (0)