3

I would like to plot multiple swarmplots in a single figure. I think swarmplot is one of the seaborn plots that should be able to do this, as it takes an axes keyword. However (with a freshly updated anaconda, matplotlib and seaborn) the following code :

import seaborn as sb
import matplotlib.pyplot as plt
tips = sb.load_dataset("tips")
f, ax = plt.subplots(2,2)
sb.swarmplot(x="size", y="total_bill", data=tips, axes=ax[0,0])

Gives the following error (at the end of a long traceback):

ValueError: Can not reset the axes.  You are probably trying to re-use an artist in more than one Axes which is not supported

I Googled and can't find any mention of this error. Is it not possible to draw a swarmplot into a subplot?

Thanks.

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Tobias Wood
  • 139
  • 8

1 Answers1

4

You want to use ax=, not axes=.

mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • 1
    Thank you very much. Strangely (to me) `axes=` works when a figure has a single axis. – Tobias Wood May 16 '16 at 15:15
  • 1
    Keyword arguments get passed through to `plt.scatter`. It looks like that does something with `axes`, though I'm not sure what. – mwaskom May 16 '16 at 21:12
  • It might just be calling `plt.figure.gca` internally and doing nothing with `axes`. – jackl Sep 19 '21 at 19:23