Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: AxesSubplot.get_yticks not returning the actual printed ticks #23717

Closed
@suuuehgi

Description

@suuuehgi

Bug summary

get_x/yticks seems to have some padding but does not return the actual printed ticks.

Code for reproduction

fig, ax = plt.subplots()
ax.loglog( range(100), range(100) )
print( ax.get_yticks() )
array([1.e-02, 1.e-01, 1.e+00, 1.e+01, 1.e+02, 1.e+03, 1.e+04])

so1

Actual outcome

fig, ax = plt.subplots()
ax.loglog( range(100), range(100) )

ax2 = ax.twinx()
ax2.set_yscale('log')
ax2.set_ylim( ax.get_ylim() )

yields a correct visual equivalence

so2

but adding ax2.set_yticks( ax.get_yticks() )

fig, ax = plt.subplots()
ax.loglog( range(100), range(100) )

ax2 = ax.twinx()
ax2.set_yscale('log')
ax2.set_ylim( ax.get_ylim() )

ax2.set_yticks( ax.get_yticks() ) # <---

yields:
so3

Expected outcome

Both axes with equal visual appearance when using ax2.set_yticks( ax.get_yticks() ).

Additional information

Why is this behavior problematic?

Consider e.g.:

ax2.set_yticks( ticks=ax.get_yticks(), 
                labels=[ "{:.2f}".format( my_transform(i) ) for i in ax.get_yticks() ] )

Thanks for any help / investigation!

Operating system

Arch

Matplotlib Version

3.5.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.5

Jupyter version

jupyter lab --version == 3.4.4

Installation

Linux package manager

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions