Skip to content

Axis labels only move with spines if there are ticks #3715

Closed
@jkseppan

Description

@jkseppan

The following code plots some random data and moves the spines outward. It works just as expected if it leaves the automatic tick labels alone, but if it disables them the axis labels do not move with the spines. This is on the v1.4.x branch.

import numpy as np
from matplotlib import pyplot as plt

for ticks in True, False:
    fig, ax = plt.subplots(figsize=(10,8), dpi=100)
    plt.subplots_adjust(left=0.3, bottom=0.3)
    data = np.random.uniform(size=100)
    ax.plot(data)
    ax.yaxis.set_ticks_position('left')
    ax.spines['left'].set_position(('outward', 30))
    ax.spines['right'].set_visible(False)
    ax.set_ylabel('random numbers')
    ax.xaxis.set_ticks_position('bottom')
    ax.spines['bottom'].set_position(('outward', 30))
    ax.spines['top'].set_visible(False)
    ax.set_xlabel('sequence')
    if not ticks:
        ax.xaxis.set_ticks([])
        ax.yaxis.set_ticks([])
    plt.savefig('ticks-%s.png' % ticks)

The output with ticks enabled:

ticks-true

and with ticks disabled:

ticks-false

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions