將Seaborn 圖例放置在不同位置
使用Seaborn 的因子圖建立條形圖時,可能會遇到放錯位置的圖例。為了解決這個問題,可以自訂圖例位置。
具有圖例自訂的 Seaborn
不要使用預設的右中圖例位置,而是使用更合適的圖例位置可以指定位置。一種方法是在 Factorplot 中設定 legend=False 並使用 Matplotlib 手動建立圖例。
提供的解決方案擴展了此技術:
<code class="python">import seaborn as sns import matplotlib.pyplot as plt sns.set(style="whitegrid") titanic = sns.load_dataset("titanic") g = sns.factorplot("class", "survived", "sex", data=titanic, kind="bar", size=6, palette="muted", legend=False) g.despine(left=True) plt.legend(loc='upper left') g.set_ylabels("survival probability")</code>
使用這些方法,您可以將圖例放置在所需的位置,從而提高seaborn 繪圖的可讀性和清晰度。
以上是以下是您文章的一些標題選項,重點關注問題格式和有關 Seaborn 圖中圖例定位的核心內容: **選項 1(直接且簡潔):** * **如何定位 L的詳細內容。更多資訊請關注PHP中文網其他相關文章!