📜  如何在 seaborn 中重叠两个条形图 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:51.248000             🧑  作者: Mango

代码示例1
# instead of seaborn use plt.bar 

import matplotlib.pyplot as plt
import seaborn as sns

# Load the example car crash dataset
crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)

# states of interest
txcahi = crashes[crashes['abbrev'].isin(['TX','CA','HI'])]

# Plot the total crashes
f, ax = plt.subplots(figsize=(10, 5))
plt.xticks(rotation=90, fontsize=10)

plt.bar(height="total", x="abbrev", data=crashes, label="Total", color="lightgray")
plt.bar(height="total", x="abbrev", data=txcahi, label="Total", color="red")

sns.despine(left=True, bottom=True)