我是Python新手。
我使用以下代码在 matplotlib/seaborn 中生成了一个箱线图(带有群图覆盖)。我现在想添加一个遵循每个框的配色方案的图例。我在网上找到的许多解决方案似乎不适用于这种特定类型的图表(例如,仅适用于分组箱线图)。
当我尝试实现此处建议的代码时,我收到错误消息。
非常感谢所有的输入!
# Import libraries and modules
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Set seaborn style.
sns.set(style="whitegrid", palette="colorblind")
# Load summary tidy data.
tidy = pd.read_csv('tidy.csv')
# Define plots for tidy data
fig, ax = plt.subplots(figsize=(10,6))
ax = sns.boxplot(x='header1', y='header2', data=tidy, order=["header1", "header2"])
ax = sns.swarmplot(x="header1", y="header2", data=tidy, color=".25", order=["header1", "header2"])
labels = [item.get_text() for item in ax.get_xticklabels()]
labels[0] = 'header1'
labels[1] …Run Code Online (Sandbox Code Playgroud)