Reputation: 1949
I am drawing a few overlaid plots, and I want to pass the same arguments to different functions. I'm wondering if this is possible?
For example:
import seaborn as sns
tips = sns.load_dataset("tips")
#instead of this
ax = sns.boxplot(x="day", y="total_bill", data=tips)
ax = sns.swarmplot(x="day", y="total_bill", data=tips, color=".25")
#something like this
my_kwargs=(x="day", y="total_bill", data=tips)
ax = sns.boxplot(my_kwargs)
ax = sns.swarmplot(my_kwargs, color=".25")
Is something like this possible at all?
I'm aware I can pre-define each of them as a variable, and then specify them inside each function. But I'm wondering if there is something better than this
Upvotes: 1
Views: 32
Reputation: 27360
You're almost there:
my_kwargs = dict(x="day", y="total_bill", data=tips)
ax = sns.boxplot(**my_kwargs)
ax = sns.swarmplot(color=".25", **my_kwargs) # ** must be last
Upvotes: 3