Skip to content

Adding Text Annotation when Co-plotting Shrinks Subplots when Tight Layout is Applied #18098

@Aerovet

Description

@Aerovet

Bug report

Bug summary

Vertical annotations shrink subplots when a figure handle's tight_layout is set to True. The expectation is that annotations would overlap the subplots.

Looking at the documentation...

https://matplotlib.org/3.2.2/tutorials/intermediate/tight_layout_guide.html#caveats

tight_layout() only considers ticklabels, axis labels, and titles. Thus, other artists may be clipped and also may overlap

With that in mind, tight_layout should not consider Text annotations, and shouldn't adjust the subplot size when added.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,np.pi*2,1000)
y = np.sin(x)
dy = np.cos(x)
dy2 = -np.sin(x)

for b in [False,True]:

    h, ax = plt.subplots(3,1,sharex = True)
    h.set_tight_layout(b)
    ax[0].plot(x,y)
    ax[1].plot(x,dy)
    ax[2].plot(x,dy2)

    ax[2].annotate(s = f'Annotation When Tight Layout is {b}', xy = (np.pi,-1), rotation = 'vertical')

Actual outcome

image

Expected outcome

In this case, tight_layout is set to FALSE just to see visually what it looks like with the text overlayed

image

Matplotlib version

  • Operating system: CentOS Linux 7 (Core)
  • Matplotlib version: 3.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.8.3
  • Jupyter version (if applicable):
  • Other libraries: numpy 1.18.5

conda

conda-forge

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy