2

Hello, I am currently learning matplotlib. I have just learnt about figures and the add_axes() method. For the add_axes() method, you pass in a list containing [left, bottom, width, height].

Obviously, width and height controls the width and height of the graph, but what does left and bottom do?

Here is my add_axes() -> axes = figure.add_axes([0.1, 0.1, 0.6, 0.6])

I keep changing left and bottom, but nothing on the plot is changing. I read the matplotlib documentation on figure.add_axes(), but it did not explain what left and bottom did.

Thank you!

theProCoder
  • 390
  • 6
  • 21

1 Answers1

2

Description and example of mpl.figure.add_axes

mpl.figure.add_axes(rect, projection=None, polar=False, **kwargs) 

Adds an axis to the current figure or a specified axis.
From the matplotlib mpl.figure.ad_axes method documentation:
rect: sequence of floats. The dimensions [left, bottom, width, height] of the new Axes. All quantities are in fractions of figure width and height.

  • left = how far from the left of the figure (like a x value)
  • bottom = how far from the bottom of the figure (like a y value)

Here is a quick google search
Here is an example:

fig, ax1 = plt.subplots(figsize=(12,8))
ax2 = fig.add_axes([0.575,0.55,0.3,0.3])

ax1.grid(axis='y', dashes=(8,3), color='gray', alpha=0.3)
for ax in [ax1, ax2]:
    [ax.spines[s].set_visible(False) for s in ['top','right']]

enter image description here

Coup
  • 695
  • 4
  • 6
  • 1
    Thanks for the answer. 1 question though. You say `left` and `bottom` are how far from the left and bottom of the figure. But what is the thing that is that much away from the figure? Like, `bottom and left define how far ? is away from the figure ` – theProCoder Jul 16 '21 at 06:06
  • All quantities are in fractions of figure width and height. – Coup Jul 16 '21 at 06:09