Skip to content

[Bug]: tick_top and sharex do not work together #30219

Open
@carissableker

Description

@carissableker

Bug summary

I expected tick_top to add ticks on the top of the uppermost subplot when using sharex=True. However, it adds ticks to the lower subplot (as it would normally), making it incompatible with shared axes.

Code for reproduction

import matplotlib.pyplot as plt

fig, axes = plt.subplots(
    sharex=True, sharey=True, 
    ncols=2, nrows=2
)
axes = axes.flatten()
for ax in axes:
    sc = ax.scatter(
        x=[0, 1, 5, 3], 
        y=[0, 1, 2, 4], 
    )

    ax.xaxis.tick_top()
    ax.tick_params(axis='x', rotation=55)

Actual outcome

Image

Expected outcome

Image

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.8.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions