2

Having the following code to generate matplotlib subplots:

import matplotlib.pyplot as plt
x = [1,2,3]
y = [4,5,6]

fig, ax = plt.subplots(1, 2, figsize=(10, 10))
ax[0].plot(x, y)
ax[1].plot(x, y)

I can get figure size using:

h = fig.get_figheight()
w = fig.get_figwidth()
print(h, w)

A bit surprisingly, I get 9.98 10.0, but anyway it agrees with figsize=(10, 10). My questions is how can I get the subfigure size from axes, in this case ax[0] and ax[1] just like using fig to get the size?

Jiadong
  • 1,822
  • 1
  • 17
  • 37
  • The first 2 lines of the answer in the duplicate shows how to get the size in inches. You can leave out the rest if you do not want it in pixels – DavidG Nov 30 '18 at 09:27
  • Thank you! I also found another methods, using get_position() to get the bbox, and extract the fractional coords. Appreciate your help!!! – Jiadong Nov 30 '18 at 09:29

0 Answers0