Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Understandable. A reason why I keep going back and forth between matplotlib and seaborn in the past is due to not knowing how to customize seaborn. Now that I know they are just regular matplotlib objects, it's very easy to mix and match them when seaborn is just too opinionated. You can read more here https://seaborn.pydata.org/tutorial/introduction.html#opinio...

Some examples I did recently: to set the layout engine of a seaborn plot

    g = sns.relplot(df, x="value", y="y", col="variable", col_wrap=3)
    g.figure.set_layout_engine("constrained")
    g.figure.set_size_inches(16, 12)
Set the subplot titles

    g = sns.displot(df, x="value", col="model")
    g.figure.set_size_inches(16, 8)
    for (ax, title) in zip(g.axes[0], titles):
        ax.set_title(f"Title: {title}")
Multiple seaborn plots with two lines, error band, and scatter placed onto existing matplotlib subplots and custom colors

  colors = sns.color_palette()
  fig, axs = plt.subplots(1, len(ys), sharey=True, figsize=(16, 6), constrained_layout=True)
  for (X, y, ax, title) in zip(Xs, ys, axs, titles):
    sns.lineplot(x=X, y=y, color=colors[0], ax=ax)
    sns.lineplot(x=X, y=y_predict, color=colors[1], ax=ax)
    ax.fill_between(X, y_predict - std, y_predict + std, color=colors[1], alpha=0.3)
    
    sns.scatterplot(x=X_train, y=y_train, alpha=0.7, color=colors[7], ax=ax)
    
    ax.set_title(title)
    ax.tick_params(rotation=0)
(You can also prepare the data in pandas the way seaborn like it and create faceted plot declaratively; the point is you can mix and match them freely and intuitively.)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: