<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Load example data
data = np.random.normal(size=100)

# Create histogram plot with legend label
sns.histplot(data, label='Total Bills')

# Add legend and set title
plt.legend(title=&quot;Legend Title&quot;)
plt.title(&quot;Histogram Plot with Single Legend Label&quot;)

# Show plot
plt.show()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">seaborn</span> <span class="pl-k">as</span> <span class="pl-s1">sns</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-c"># Load example data</span>
<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">normal</span>(<span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-c1">100</span>)

<span class="pl-c"># Create histogram plot with legend label</span>
<span class="pl-s1">sns</span>.<span class="pl-en">histplot</span>(<span class="pl-s1">data</span>, <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'Total Bills'</span>)

<span class="pl-c"># Add legend and set title</span>
<span class="pl-s1">plt</span>.<span class="pl-en">legend</span>(<span class="pl-s1">title</span><span class="pl-c1">=</span><span class="pl-s">"Legend Title"</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">title</span>(<span class="pl-s">"Histogram Plot with Single Legend Label"</span>)

<span class="pl-c"># Show plot</span>
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto">The code gives me:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/32328286/219003864-12eab7e3-71b9-4246-a70a-37e2a7a37b2b.png"><img src="https://user-images.githubusercontent.com/32328286/219003864-12eab7e3-71b9-4246-a70a-37e2a7a37b2b.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">How can I let it show only one legend label? Thanks!</p>
<p dir="auto">The following code results in a segmentation fault if fastcluster is not installed :</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy
import seaborn
a = [ [ 1,2,3,numpy.inf ], 
      [ 1,2,3,numpy.inf ], 
      [ 1,2,3,numpy.inf ], 
      [ 1,2,3,numpy.inf ] ]
seaborn.clustermap( a )"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span>
<span class="pl-k">import</span> <span class="pl-s1">seaborn</span>
<span class="pl-s1">a</span> <span class="pl-c1">=</span> [ [ <span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-s1">numpy</span>.<span class="pl-s1">inf</span> ], 
      [ <span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-s1">numpy</span>.<span class="pl-s1">inf</span> ], 
      [ <span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-s1">numpy</span>.<span class="pl-s1">inf</span> ], 
      [ <span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-s1">numpy</span>.<span class="pl-s1">inf</span> ] ]
<span class="pl-s1">seaborn</span>.<span class="pl-en">clustermap</span>( <span class="pl-s1">a</span> )</pre></div>
<p dir="auto">Most (all?) distance metrics in <code class="notranslate">scipy.distance.pdist</code> will fail produce valid output if the matrix contains <code class="notranslate">inf</code> or <code class="notranslate">nan</code>, but someone should probably raise an exception somewhere before things devolve badly enough to take down the interpreter.</p>