Skip to content

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 22, 2019

PR Summary

Titles are supposed to avoid tick labels as of #9498. However, if ticks are labeled at the top and bottom of a plot, ax.xaxis.get_ticks_position() returns "unknown" instead of "top", so old logic didn't move title above tick labels on the top of the axes for that case.

Closes #13735

import pandas as pd
import numpy as np
import string
import matplotlib.pyplot as plt

n = 10
names = ['Long Name ' + suffix for suffix in string.ascii_uppercase[:n]]

fig = plt.figure(constrained_layout=True)
ax = plt.gca()

ax.set_xticks(np.arange(n))
ax.set_xticklabels(names)
ax.set_yticks(np.arange(n))
ax.set_yticklabels(names)

# Set ticks on both sides of axes on
ax.tick_params(axis="x", bottom=True, top=True, labelbottom=True, labeltop=True)
# Rotate and align bottom ticklabels
plt.setp([tick.label1 for tick in ax.xaxis.get_major_ticks()], rotation=45,
         ha="right", va="center", rotation_mode="anchor")
# Rotate and align top ticklabels
plt.setp([tick.label2 for tick in ax.xaxis.get_major_ticks()], rotation=45,
         ha="left", va="center",rotation_mode="anchor")

ax.set_title("Name Co-Occurrences")
plt.show()

Before

titleissold

After

titleissnew

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak marked this pull request as ready for review March 23, 2019 04:36
@jklymak
Copy link
Member Author

jklymak commented Mar 23, 2019

The doc build has been flakey lately - I don't think this has anything to do w/ this PR...

@jklymak jklymak added this to the v3.1.1 milestone Mar 23, 2019
@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Mar 23, 2019
@timhoffm
Copy link
Member

Not sure, what's failing the doc build. The only thing I've found in the log is #13743. But that's been around for some time.

@jklymak jklymak force-pushed the fix-move-title-ticklabels branch from 851967f to b3b3659 Compare March 23, 2019 14:49
@jklymak jklymak force-pushed the fix-move-title-ticklabels branch from b3b3659 to 6f0b9a0 Compare March 24, 2019 15:32
@jklymak jklymak force-pushed the fix-move-title-ticklabels branch from 6f0b9a0 to b4a1a97 Compare March 25, 2019 03:54
@jklymak
Copy link
Member Author

jklymak commented Mar 25, 2019

This is a pretty small fix that would be nice to get in for 3.1 if anyone els had a minute to check it.

@anntzer anntzer merged commit 20387f7 into matplotlib:master Mar 25, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 25, 2019
jklymak added a commit that referenced this pull request Mar 25, 2019
…741-on-v3.1.x

Backport PR #13741 on branch v3.1.x (FIX: make title move above ticklabels)
@QuLogic QuLogic modified the milestones: v3.1.1, v3.1.0 Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

title doesn't move for ticklables....
5 participants