Skip to content

Titles cannot be padded to negative numbers anymore. #16805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ImportanceOfBeingErnest opened this issue Mar 17, 2020 · 6 comments · Fixed by #17127
Closed

Titles cannot be padded to negative numbers anymore. #16805

ImportanceOfBeingErnest opened this issue Mar 17, 2020 · 6 comments · Fixed by #17127
Assignees
Milestone

Comments

@ImportanceOfBeingErnest
Copy link
Member

Bug report

Bug summary

Titles cannot be padded to negative numbers anymore.
Only if no xticklabels are on the axes, it still works as expected.

This broke in #13741 (sorry for approving that one)

Code for reproduction

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(ncols=2)
for ax in (ax1, ax2):
    ax.set_title(f"Title 1", pad=-20)

ax1.tick_params(labelbottom=False)

plt.show()

Actual outcome

image

Expected outcome

image

Matplotlib version

  • Operating system:
  • Matplotlib version: 3.1
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:
@ImportanceOfBeingErnest ImportanceOfBeingErnest added this to the v3.2.1 milestone Mar 17, 2020
@tacaswell
Copy link
Member

This broke in #13741 (sorry for approving that one)

Given the scale and connectivity of Matplotlib missing higher-order consequences of changes is inevitable. We should do our best to not make mistakes, but it is also expected that we will all miss something from time to time.

Is there a simple fix for this? I'm 50/50 in putting this in 3.2.x bug fix vs 3.3 (been broken for a while, but also definitely looks like a bug that no one would be relying on unless someone discovered that setting a negative pad "suctions" the title to the top of the axes).

@ImportanceOfBeingErnest
Copy link
Member Author

I don't see any simple fix for now. Essentially this shows that coupling the two otherwise distinct properties may not have been the best idea.
Feel free to remilestone.

@tacaswell tacaswell modified the milestones: v3.2.1, v3.3.0 Mar 17, 2020
@jklymak
Copy link
Member

jklymak commented Mar 17, 2020

Well update_title_pos tries to position the text above the xticks and xlabels. I guess we could just not call the update if there is a pad or just set the position assuming pad==0 and then pad.

FWIW I would imagine you get similar bugs with pad for xlabel and ylabel which update_title_pos was based on.

Note I’m pretty sure the user can still specify y for the title and have it be where they want it to be.

I guess my preference would be to not auto position if the user has set pad.

@ImportanceOfBeingErnest
Copy link
Member Author

Yes, but there is always a pad set through rcParams["axes.titlepad"] = 6.0. And I don't currently have any good idea about how to distinguish the cases, i.e. how would we ever know what the user actually wanted?

@jklymak
Copy link
Member

jklymak commented Mar 17, 2020

Perhaps you've looked at it more carefully than me, but its set to None in the signature. It seems that we just track if its None?

FWIW, we also have the same problem for y=1.0 with title. The workaround for now is:

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(ncols=2)
for ax in (ax1, ax2):
    ax.set_title(f"Title 1", pad=-20, y=1.000001)
ax1.tick_params(labelbottom=False)
plt.show()

which turns off the auto positioning. We just need to extend that logic to pad....

@jklymak
Copy link
Member

jklymak commented Mar 21, 2020

One liner if we can assume pad=-20 is meant to be manually placed (i.e. the -20 is relative to y=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants