0

I am doing some visualization in Google Colabs with pyplot and seaborn.

Trying use fig, axes to get 6 plots but on testing I get all plots in one. Any ideas as of why? Is it a Colabs problem or is it me?

fig, axes = plt.subplots(2,3,figsize=(15,10))
axes[0] = plt.plot([1, 2, 3, 4])
axes[1] = plt.plot([2, 2, 3, 4])
axes[2] = plt.plot([3, 2, 3, 4])
axes[3] = plt.plot([4, 2, 3, 4])
axes[4] = plt.plot([5, 2, 3, 4])
axes[5] = plt.plot([6, 2, 3, 4])

How it looks

Been trying to google and searching stack but without finding a solution.

Kindly Andy

Andykjb
  • 9
  • 2
  • It's unclear why you added the Seaborn tag to the post. For Seaborn's axes-level functions you need e.g. `sns.histplot(..., ax=axes[0,0])`. Figure-level functions, e.g. `sns.catplot(...)` create their own figure and subplots. – JohanC Jun 20 '22 at 14:21
  • Hi, yeah sorry I see that now. I'm planning on using the seaborn lmplot but just tried it out with a plt plot to see how it acted. – Andykjb Jun 21 '22 at 06:08

1 Answers1

0

You need to apply the .plot method on the Axis objects:

fig, axes = plt.subplots(2,2,figsize=(15,10))
axes[0, 0].plot([1, 2, 3, 4], [1, 2, 3, 4])
axes[0, 1].plot([2, 2, 3, 4], [1, 2, 3, 4])
axes[1, 0].plot([1, 2, 3, 4], [1, 2, 3, 4])
axes[1, 1].plot([2, 2, 3, 4], [1, 2, 3, 4])
mrzo
  • 2,002
  • 1
  • 14
  • 26