Skip to content

secondary axis fails to respect major tick locator #16416

@amedlin

Description

@amedlin

Bug report

Y tick locations on secondary y-axis are ignored

I create a secondary y-axis on a plot and set custom y tick locations. But my specified tick locations get ignored. In this example the right hand y-axis should have ticks at positions [1, 2, 5, 10].

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

x = np.arange(1, 100)
y = np.sqrt(x)
ax.plot(x, y)
ax.set_xlim(0, 100)
ax.set_ylim(1, 10)
secax = ax.secondary_yaxis('right', functions=(lambda z: 10*np.log10(z), lambda z: np.power(10.0, z/10.0)))
# Secondary y-axis tick locations get ignored.
secax.set_yticks([1, 2, 5, 10])
plt.show()
plt.close()

Actual outcome

ytick_bug

Expected outcome

I expect the right hand y-axis to be labeled with ticks at positions [1, 2, 5, 10], not [0, 2, 4, 6, 8, 10]. If I try to force this by using matplotlib.tickerFixedLocator, I still see the same problem.

Matplotlib version

  • Operating system: Windows 10 Build 10.0.18363
  • Matplotlib version: 3.1.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
  • Jupyter version (if applicable): N/A
  • Other libraries:
# packages in environment at C:\Miniconda3:
#
# Name                    Version                   Build  Channel
asn1crypto                1.3.0                    py37_0
astroid                   2.3.3                    py37_0
blas                      1.0                         mkl
ca-certificates           2020.1.1                      0
certifi                   2019.11.28               py37_0
cffi                      1.13.2           py37h7a1dbc1_0
chardet                   3.0.4                 py37_1003
colorama                  0.4.3                      py_0
conda                     4.8.2                    py37_0
conda-package-handling    1.6.0            py37h62dcd97_0
console_shortcut          0.1.1                         3
cryptography              2.8              py37h7a1dbc1_0
cycler                    0.10.0                   py37_0
freetype                  2.9.1                ha9979f8_1
icc_rt                    2019.0.0             h0cc432a_1
icu                       58.2                 ha66f8fd_1
idna                      2.8                      py37_0
intel-openmp              2019.4                      245
isort                     4.3.21                   py37_0
jpeg                      9b                   hb83a4c4_2
kiwisolver                1.1.0            py37ha925a31_0
lazy-object-proxy         1.4.3            py37he774522_0
libpng                    1.6.37               h2a8f88b_0
matplotlib                3.1.3                    py37_0
matplotlib-base           3.1.3            py37h64f37c6_0
mccabe                    0.6.1                    py37_1
menuinst                  1.4.16           py37he774522_0
mkl                       2019.4                      245
mkl-service               2.3.0            py37hb782905_0
mkl_fft                   1.0.15           py37h14836fe_0
mkl_random                1.1.0            py37h675688f_0
numpy                     1.18.1           py37h93ca92e_0
numpy-base                1.18.1           py37hc3f5095_1
openssl                   1.1.1d               he774522_3
pandas                    0.25.3           py37ha925a31_0
patsy                     0.5.1                    py37_0
pip                       20.0.2                   py37_1
powershell_shortcut       0.0.1                         2
pycosat                   0.6.3            py37he774522_0
pycparser                 2.19                     py37_0
pylint                    2.4.4                    py37_0
pyopenssl                 19.1.0                   py37_0
pyparsing                 2.4.6                      py_0
pyqt                      5.9.2            py37h6538335_2
pysocks                   1.7.1                    py37_0
python                    3.7.4                h5263a28_0
python-dateutil           2.8.1                      py_0
pytz                      2019.3                     py_0
pywin32                   227              py37he774522_1
qt                        5.9.7            vc14h73c81de_0
requests                  2.22.0                   py37_1
ruamel_yaml               0.15.87          py37he774522_0
scipy                     1.3.2            py37h29ff71c_0
seaborn                   0.9.0              pyh91ea838_1
setuptools                45.1.0                   py37_0
sip                       4.19.8           py37h6538335_0
six                       1.14.0                   py37_0
sqlite                    3.31.1               he774522_0
statsmodels               0.11.0           py37he774522_0
tornado                   6.0.3            py37he774522_0
tqdm                      4.42.0                     py_0
urllib3                   1.25.8                   py37_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.16.27012          hf0eaf9b_1
wheel                     0.34.2                   py37_0
win_inet_pton             1.1.0                    py37_0
wincertstore              0.2                      py37_0
wrapt                     1.11.2           py37he774522_0
xlrd                      1.2.0                    py37_0
yaml                      0.1.7                hc54c509_2
zlib                      1.2.11               h62dcd97_3

Installed via Miniconda distro, standard channels for packages.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions