1 回答
TA贡献1836条经验 获得超5个赞
首先,我将 0.0 值替换为 NaN。但这还不够,因为问题的很大一部分是添加的水平线,以替换底部书脊,这掩盖了曲线在不同点停止的事实。如果删除这些内容,则只剩下:
就个人而言,我并没有过分发现刻度白线,这使得左右的狭窄区域非常薄。我倾向于删除它们:
完整代码:
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
sns.set(style="whitegrid", rc={"axes.facecolor": (0, 0, 0, 0)})
df = pd.read_csv('https://gist.githubusercontent.com/willemvanopstal/c2892e68d6eb94194acd371e49d949bd/raw/642c4261198f0cacdf32aad21aebca5953c6cd75/stats_together_data.csv', delimiter=';')
df.loc[df["aandeel"]==0,"aandeel"]=np.nan
# Initialize the FacetGrid object
pal = sns.color_palette("Set2")
g = sns.FacetGrid(df, row="process", hue="process", aspect=10, height=0.6, palette=pal)
# Draw the densities in a few steps
g.map(sns.lineplot, "region", "aandeel", clip_on=False, alpha=1, lw=1.5)
g.map(plt.fill_between, "region", "aandeel", interpolate=True)
#g.map(sns.lineplot, "region", "aandeel", clip_on=False, color="w", lw=2)
# Define and use a simple function to label the plot in axes coordinates
def label(x, color, label):
ax = plt.gca()
ax.text(0, .2, label, fontweight="bold", color=color,
ha="left", va="center", transform=ax.transAxes)
g.map(label, "region")
# Set the subplots to overlap
g.fig.subplots_adjust(hspace=-.25)
# Remove axes details that don't play well with overlap
g.set_titles("")
g.set(yticks=[])
g.set(xticks=df.region[0::1])
g.despine(bottom=True, left=True)
plt.show()
添加回答
举报