Я хотел рассчитать смещение оси для seaborn.despine () динамически. Он должен придерживаться значения 0 моих осей matplotlib. Но почему-то кажется, что у меня неправильная концепция расчета.
Поскольку мне нужно установить смещение Морского Рога в точках, я попытался рассчитать размер изображения и установить его пропорционально оси X с помощью, но как это видно из небольшого примера кода ниже т работать как хотелось.
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Define and use a simple function to label the plot in axes coordinates
def label(x, color, label):
ax = plt.gca()
ax.text(0, .2, label, fontweight="bold", color=color,
ha="left", va="center", transform=ax.transAxes)
# Create sample data
rs = np.random.RandomState(1979)
x = rs.randn(500)
g = np.tile(list("ABCDEFGHIJ"), 50)
df = pd.DataFrame(dict(x=x, g=g))
# Plot
sns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)})
pal = sns.color_palette("hls")
# Initialize the FacetGrid object
g = sns.FacetGrid(df, row="g", hue="g", aspect=20, height=0.7, palette=pal)
# Draw the densities in a few steps
g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=0.7, lw=2, bw='scott')
g.map(sns.kdeplot, "x", clip_on=False, color="k", lw=1, bw='scott')
g.map(label, "x")
# Set the subplots to overlap
g.fig.subplots_adjust(hspace=-.25)
# calculate offset for left axis
ax = g.axes[0]
ax_size = abs(ax[0].get_xlim()[0]) + ax[0].get_xlim()[1]
fig = g.fig
size = fig.get_size_inches()*fig.dpi
fig_size = size[0]
off = fig_size * ax[0].get_xlim()[0] / ax_size
# Remove axes details that don't play well with overlap
g.set_titles("")
g.set(yticks=[])
g.despine(bottom=False, left=False, offset={'left':off}); # set offset
график выглядит так: ![Plot](https://i.stack.imgur.com/dS8Cm.png)
Как видно, ось отклонена от нулевого значения. У кого-нибудь есть идеи, как сделать это правильно?
Заранее спасибо,
Exi