Skip to content
Advertisement

How to plot figures to different subplot axes in matplotlib

I was trying to plot a figure with a combination of a 3d subplot and 3 2d ones. Why do they overlap each other?

enter image description here

Here are my codes:

JavaScript

Advertisement

Answer

  • In each group, an ax is created with ax = fig.add_subplot(3, 2, 1, projection='3d'), but then you reassign the variable with ax = plt.axes(projection='3d'); this does not plot to ax.
  • To plot to a specific axes, use the ax parameter in the plot method
    • sns.histplot(df['freq: 1x'], ax=ax)
  • Also, upgrade seaborn to version 0.11, because sns.distplot is deprecated for displot or histplot.
JavaScript

enter image description here

Using matplotlib gridspec

JavaScript

enter image description here

Advertisement