Skip to content

Conversation

ponnhide
Copy link
Contributor

PR Summary

I developed patchworklib inspired by the patchwork library for R.
Patchworklib allows users to freely arrange multiple matplotlib plots with "|" and "/" operators, as follows.

import seaborn as sns
import patchworklib as pw
fmri = sns.load_dataset("fmri")

ax1 = pw.Brick("ax1", figsize=(3,2))
sns.lineplot(x="timepoint", y="signal", hue="region", style="event", data=fmri, ax=ax1)
ax1.move_legend(new_loc='upper left', bbox_to_anchor=(1.05, 1.0))
ax1.set_title("ax1")

ax2 = pw.Brick("ax2", figsize=(1,2))
sns.barplot(x="sex", y="survived", hue="class", data=titanic, ax=ax2)
ax2.move_legend(new_loc='upper left', bbox_to_anchor=(1.05, 1.0))
ax2.set_title("ax2")

ax3 = pw.Brick("ax3", (5,2))
sns.histplot(diamonds, x="price", hue="cut", multiple="stack", palette="light:m_r", edgecolor=".3", linewidth=.5, log_scale=True, ax = ax3)
ax3.move_legend(new_loc='upper left', bbox_to_anchor=(1.0, 1.0))
ax3.set_title("ax3")

((ax1 | ax2) / ax3).savefig() 

Also, you can quickly test another layout.

ax3.change_aspectratio((5,2))
ax2.change_aspectratio((1,3))
((ax1 / ax3) | ax2).savefig()

I hope you will add patchworklib to the mpl-third-party list.
Thank you.

@ponnhide ponnhide changed the title Add patchworklib.yml. Add patchworklib.yml Jan 12, 2022
@jklymak
Copy link
Member

jklymak commented Jan 12, 2022

I'll merge, but only the auto doc build didn't run?

@jklymak jklymak merged commit 9165661 into matplotlib:main Jan 12, 2022
@jklymak
Copy link
Member

jklymak commented Jan 12, 2022

Thanks @ponnhide - also looks like a cool package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants