File: inset_locator_demo.py

package info (click to toggle)
matplotlib 1.1.1~rc2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 66,076 kB
  • sloc: python: 90,600; cpp: 69,891; objc: 5,231; ansic: 1,723; makefile: 171; sh: 7
file content (45 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (4)
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
import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar


def add_sizebar(ax, size):
   asb =  AnchoredSizeBar(ax.transData,
                         size,
                         str(size),
                         loc=8,
                         pad=0.1, borderpad=0.5, sep=5,
                         frameon=False)
   ax.add_artist(asb)


fig = plt.figure(1, [5.5, 3])

# first subplot
ax = fig.add_subplot(1,2,1)
ax.set_aspect(1.)

axins = inset_axes(ax,
                   width="30%", # width = 30% of parent_bbox
                   height=1., # height : 1 inch
                   loc=3)

plt.xticks(visible=False)
plt.yticks(visible=False)


# second subplot
ax = fig.add_subplot(1,2,2)
ax.set_aspect(1.)

axins = zoomed_inset_axes(ax, 0.5, loc=1) # zoom = 0.5

plt.xticks(visible=False)
plt.yticks(visible=False)

add_sizebar(ax, 0.5)
add_sizebar(axins, 0.5)

plt.draw()
plt.show()