Skip to content

[Bug]: subplot_mosaic bug with empty_sentinel and sharey=True #25417

Description

@apicco

Bug summary

When an empty sentinel is used at the beginning of a row, with the sharey option True, the tick labelling on the y-axis isn't shown.

Code for reproduction

from matplotlib import pyplot as plt
import numpy as np

data = [ np.array( [ i for i in range( 100 ) ] ) , np.random.random( 100 ) ]

fig1 = plt.figure()

# create a mosaic with an empty_sentinel 
# at the END of the row. 
# 'sharey=True' works.
subplots = fig1.subplot_mosaic(
        """
        AB.
        CDE
        """ , sharex = True , sharey = True )

subplots[ "A" ].plot( data[0] , data[1] )
subplots[ "B" ].plot( data[0] , data[1] )
subplots[ "C" ].plot( data[0] , data[1] )
subplots[ "D" ].plot( data[0] , data[1] )
subplots[ "E" ].plot( data[0] , data[1] )

subplots[ "C" ].set_xlabel( 'A variable' )
subplots[ "D" ].set_xlabel( 'A variable' )
subplots[ "E" ].set_xlabel( 'A variable' )

subplots[ "A" ].set_ylabel( 'Some data' )
subplots[ "C" ].set_ylabel( 'Some data' )

plt.savefig( 'mosaic_working.pdf' )

# create a mosaic with an empty_sentinel 
# at the start of the row. 
# 'sharey=True' DOESN'T work: the y ticks
# are missing.
fig2 = plt.figure()

subplots = fig2.subplot_mosaic(
        """
        .AB
        CDE
        """ , sharey = True )

subplots[ "A" ].plot( data[0] , data[1] )
subplots[ "B" ].plot( data[0] , data[1] )
subplots[ "C" ].plot( data[0] , data[1] )
subplots[ "D" ].plot( data[0] , data[1] )
subplots[ "E" ].plot( data[0] , data[1] )

subplots[ "C" ].set_xlabel( 'A variable' )
subplots[ "D" ].set_xlabel( 'A variable' )
subplots[ "E" ].set_xlabel( 'A variable' )

subplots[ "A" ].set_ylabel( 'Some data' )
subplots[ "C" ].set_ylabel( 'Some data' )

plt.savefig( 'mosaic_not_working.pdf' )

Actual outcome

mosaic_working.pdf
mosaic_not_working.pdf

Expected outcome

The y-axis in the first subplot of the top row should have y ticks.

Additional information

No response

Operating system

OS

Matplotlib Version

3.7.0

Matplotlib Backend

No response

Python version

3.11

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions