<p dir="auto">I wanted to make a FacetGrid plot with some offset.</p>
<p dir="auto">Basic code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import seaborn as sns
sns.set(style=&quot;ticks&quot;, color_codes=True)
tips = sns.load_dataset(&quot;tips&quot;)
g = sns.FacetGrid(tips, col=&quot;time&quot;, row=&quot;smoker&quot;)
g = g.map(plt.hist, &quot;total_bill&quot;)"><pre class="notranslate"><code class="notranslate">import seaborn as sns
sns.set(style="ticks", color_codes=True)
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time", row="smoker")
g = g.map(plt.hist, "total_bill")
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/10461030/26489001/dc480cb2-4205-11e7-9313-551d0ddd2549.png"><img src="https://cloud.githubusercontent.com/assets/10461030/26489001/dc480cb2-4205-11e7-9313-551d0ddd2549.png" alt="zero" style="max-width: 100%;"></a></p>
<p dir="auto">Now with offset:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tips = sns.load_dataset(&quot;tips&quot;)
g = sns.FacetGrid(tips, col = 'time', row='sex')
g.despine(offset=10)
g = g.map(plt.hist, &quot;tip&quot;)"><pre class="notranslate"><code class="notranslate">tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col = 'time', row='sex')
g.despine(offset=10)
g = g.map(plt.hist, "tip")
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/10461030/26489030/f5803dbc-4205-11e7-9b38-05626e7b5a88.png"><img src="https://cloud.githubusercontent.com/assets/10461030/26489030/f5803dbc-4205-11e7-9b38-05626e7b5a88.png" alt="second" style="max-width: 100%;"></a></p>
<p dir="auto">So the x- and y-label return in the inner axes, which is not what I want.<br>
I looked in the code for the class definition of FacetGrid, and applied the same code to remove the labels on the inner axes.</p>
<p dir="auto">The code I used as a base for my workaround:<br>
<a href="https://github.com/mwaskom/seaborn/blob/master/seaborn/axisgrid.py#L327">link to code</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Now we turn off labels on the inner axes
if sharex:
    for ax in self._not_bottom_axes:
        for label in ax.get_xticklabels():
            label.set_visible(False)
        ax.xaxis.offsetText.set_visible(False)
if sharey:
    for ax in self._not_left_axes:
        for label in ax.get_yticklabels():
            label.set_visible(False)
        ax.yaxis.offsetText.set_visible(False)"><pre class="notranslate"><code class="notranslate"># Now we turn off labels on the inner axes
if sharex:
    for ax in self._not_bottom_axes:
        for label in ax.get_xticklabels():
            label.set_visible(False)
        ax.xaxis.offsetText.set_visible(False)
if sharey:
    for ax in self._not_left_axes:
        for label in ax.get_yticklabels():
            label.set_visible(False)
        ax.yaxis.offsetText.set_visible(False)
</code></pre></div>
<p dir="auto">generate the figure:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tips = sns.load_dataset(&quot;tips&quot;)
g = sns.FacetGrid(tips, col = 'time', row='sex')
g.despine(offset=10)
g = g.map(plt.hist, &quot;tip&quot;)

for ax in g.axes[:, 1:].flat:
    for label in ax.get_yticklabels():
        label.set_visible(False)
    ax.yaxis.offsetText.set_visible(False)
    
for ax in g.axes[:-1, :].flat:
    for label in ax.get_xticklabels():
        label.set_visible(False)
    ax.xaxis.offsetText.set_visible(False)"><pre class="notranslate"><code class="notranslate">tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col = 'time', row='sex')
g.despine(offset=10)
g = g.map(plt.hist, "tip")

for ax in g.axes[:, 1:].flat:
    for label in ax.get_yticklabels():
        label.set_visible(False)
    ax.yaxis.offsetText.set_visible(False)
    
for ax in g.axes[:-1, :].flat:
    for label in ax.get_xticklabels():
        label.set_visible(False)
    ax.xaxis.offsetText.set_visible(False)
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/10461030/26489430/9cea7292-4207-11e7-9121-36ce4c88c01d.png"><img src="https://cloud.githubusercontent.com/assets/10461030/26489430/9cea7292-4207-11e7-9121-36ce4c88c01d.png" alt="third" style="max-width: 100%;"></a></p>
<p dir="auto">My workaraound works, so no issues there. But I feel that this is not the behaviour you would expect from FacetGrid. I could not find the code in <code class="notranslate">utils/despine</code> which would be responsible for the behaviour.</p>
<p dir="auto"><a href="https://stackoverflow.com/questions/37860163/seaborn-despine-brings-back-the-ytick-labels/44161447#44161447" rel="nofollow">original stackoverflow post</a></p>
<p dir="auto">Setup:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="samples = 1

df = pd.DataFrame()

for batch_size in range(31):
  samples = samples/(1+scipy.stats.expon.rvs(loc=0, scale=1/1000, size=10000))
  df = df.append(dict(batch_size=batch_size, samples=samples), ignore_index=True)

exploded_df = df.explode(&quot;samples&quot;)"><pre class="notranslate"><code class="notranslate">samples = 1

df = pd.DataFrame()

for batch_size in range(31):
  samples = samples/(1+scipy.stats.expon.rvs(loc=0, scale=1/1000, size=10000))
  df = df.append(dict(batch_size=batch_size, samples=samples), ignore_index=True)

exploded_df = df.explode("samples")
</code></pre></div>
<p dir="auto">The following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sns.displot(data=exploded_df[exploded_df.batch_size % 10 == 0], col=&quot;batch_size&quot;, x=&quot;samples&quot;, kind=&quot;hist&quot;)"><pre class="notranslate"><code class="notranslate">sns.displot(data=exploded_df[exploded_df.batch_size % 10 == 0], col="batch_size", x="samples", kind="hist")
</code></pre></div>
<p dir="auto">takes forever (aborted after a minute or so), while</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="g = sns.FacetGrid(data=exploded_df[exploded_df.batch_size % 10 == 0], col=&quot;batch_size&quot;, sharey=False)

def plot_histplot(metric, color, data):
  sns.histplot(x=np.array(data[metric]), color=color)

g.map_dataframe(plot_histplot, &quot;samples&quot;)"><pre class="notranslate"><code class="notranslate">g = sns.FacetGrid(data=exploded_df[exploded_df.batch_size % 10 == 0], col="batch_size", sharey=False)

def plot_histplot(metric, color, data):
  sns.histplot(x=np.array(data[metric]), color=color)

g.map_dataframe(plot_histplot, "samples")
</code></pre></div>
<p dir="auto">works right away. (g.map_dataframe(sns.histplot, "samples") also takes ages, so it might be the call to np.array that speeds things up?)</p>
<p dir="auto">The first version seems to spend most of its time in:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="comp_data()-&gt;__setitem__()-&gt;_get_setitem_indexer()-&gt;_convert_to_indexer()-&gt;_get_listlike_indexer()-&gt;_reindex_non_unique()-&gt;get_indexer_non_unique()-&gt;resize()"><pre class="notranslate"><code class="notranslate">comp_data()-&gt;__setitem__()-&gt;_get_setitem_indexer()-&gt;_convert_to_indexer()-&gt;_get_listlike_indexer()-&gt;_reindex_non_unique()-&gt;get_indexer_non_unique()-&gt;resize()
</code></pre></div>
<hr>
<p dir="auto">Confounder:</p>
<p dir="auto">If I recreate explode_df using dummy data:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="exploded_df = pd.DataFrame(dict(batch_size=np.random.choice(31, 10000*31), samples=np.random.normal(size=10000*31)))"><pre class="notranslate"><code class="notranslate">exploded_df = pd.DataFrame(dict(batch_size=np.random.choice(31, 10000*31), samples=np.random.normal(size=10000*31)))
</code></pre></div>
<p dir="auto">both are fast. So it might seem there is something about the DataFrame that makes it slow?</p>
<hr>
<p dir="auto">seaborn                       0.11.2<br>
pandas                        1.1.5<br>
pandas-datareader             0.9.0<br>
pandas-gbq                    0.13.3<br>
pandas-profiling              1.4.1<br>
sklearn-pandas                1.8.0</p>
<hr>
<p dir="auto">Thanks,<br>
Andreas</p>