-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequalPixel
44 lines (43 loc) · 1.82 KB
/
equalPixel
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
def equalPixel(fig,ax,cbar,wspace=0.2,cbarspace=0.05,leftshift=None):
if leftshift is None:
leftshift=0
subplots=0
for axe in fig.axes:
if isinstance(axe ,matplotlib.axes._subplots.Subplot):
subplots+=1
if isinstance(ax,(tuple,list,np.ndarray)):
if ax[0]!=fig.axes[0]:
bAxWidth = fig.axes[0].get_position().width
else:
bAxWidth = ax[0].get_position().width
for i in range(len(ax)):
bboxAx=ax[i].get_position()
by1=bAxWidth*fig.get_figwidth()*ax[i].get_data_ratio()/fig.get_figheight()
bboxAx.y0 = 1/2-by1/2; bboxAx.y1 = 1/2+by1/2
if i==0:
bboxAx.x0+=leftshift;bboxAx.x1=bboxAx.x0+bAxWidth
if i>0:
bboxAx.x0=xright+wspace*bAxWidth
bboxAx.x1=bboxAx.x0+bAxWidth
xright=bboxAx.x1
ax[i].set_position(bboxAx)
bboxCbar = cbar.ax.get_position()
widCbar=bboxCbar.width
bboxCbar.x0 = bboxAx.x1 + cbarspace*bboxAx.width; bboxCbar.x1 = bboxCbar.x0 + widCbar;
bboxCbar.y0=bboxAx.y0; bboxCbar.y1=bboxAx.y1
cbar.ax.set_position(bboxCbar)
else:
bboxAx=ax.get_position()
if ax!=fig.axes[0]:
bAxWidth = fig.axes[0].get_position().width
else:
bAxWidth = bboxAx.width
bboxAx.x0+=leftshift;bboxAx.x1=bboxAx.x0+bAxWidth
by1=bAxWidth*fig.get_figwidth()*ax.get_data_ratio()/fig.get_figheight()
bboxAx.y0 = 1/2-by1/2; bboxAx.y1 = 1/2+by1/2
ax.set_position(bboxAx)
bboxCbar = cbar.ax.get_position()
widCbar=bboxCbar.width
bboxCbar.x0 = bboxAx.x1 + cbarspace*bboxAx.width; bboxCbar.x1 = bboxCbar.x0 + widCbar;
bboxCbar.y0=bboxAx.y0; bboxCbar.y1=bboxAx.y1
cbar.ax.set_position(bboxCbar)