Last active
May 11, 2018 14:51
-
-
Save N-McA/36d6a2573b98ca8c460c0f6b764d9954 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_perceptual_axis_center_in_figure_space(fig, ax): | |
xs = ax.get_xlim() | |
if ax.get_xscale() == 'log': | |
xs = np.log10(xs) | |
c_x = sum(xs) / 2 | |
c_x = 10**c_x | |
else: | |
c_x = sum(xs) / 2 | |
ys = ax.get_ylim() | |
if ax.get_yscale() == 'log': | |
ys = np.log10(ys) | |
c_y = sum(ys) / 2 | |
c_y = 10**c_y | |
else: | |
c_y = sum(ys) / 2 | |
return np.array(fig.transFigure.inverted().transform(ax.transData.transform([c_x, c_y]))) | |
def perceptual_center(axes, fig): | |
centers = [get_perceptual_axis_center_in_figure_space(fig, ax) for ax in axes] | |
figure_p_center = np.mean(np.array(centers), axis=0) | |
return figure_p_center | |
def perceptual_bbox_inches(axes, f): | |
figure_p_center = perceptual_center(axes, f) | |
bbox = np.array(f.bbox_inches) | |
perceptual_center_inches = f.transFigure.transform(figure_p_center) / f.dpi | |
delta = np.abs(perceptual_center_inches - bbox).max(axis=0) | |
perceptual_bbox = Bbox(np.array([ | |
perceptual_center_inches + delta, | |
perceptual_center_inches - delta, | |
])) | |
return perceptual_bbox | |
''' | |
plt.rc('text', usetex=True) | |
plt.rc('text.latex', unicode=True) | |
plt.rc('font', family='serif') | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment