Skip to content

Subplots using bad axis limits in 3.2 #17203

Closed

Description

@kannes

Bug report

Bug summary

Subplots are sometimes using bad axis limits depending on the number and layout of subplots.

I guess those axis limits are guess from what gets plotted.

This happens in 3.2.1 but not in 3.1.2. I looked through the changelogs of 3.2 releases and saw nothing about axis limits. Sorry if I missed it.

Code for reproduction

Here I plot a point at x=0, y=0:

import matplotlib.pyplot as plt

for rows in range(1, 3):
    for cols in range(1, 3):
        
        # skip single plot, no subplot there
        if rows == 1 and cols == 1: continue

        fig, axes = plt.subplots(rows, cols)

        for i, ax in enumerate(axes.ravel()):
            ax.scatter(x=0, y=0)
        
        plt.show()

Actual outcome, in 3.2.1
1_2
2_1
2_2

Expected Outcome, in 3.1.2
1_2
2_1
2_2

Matplotlib version

  • Operating system: Archlinux

  • Matplotlib version: 3.2.1 from Arch repos

  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg, module://ipykernel.pylab.backend_inline

  • Python version: 3.8.2 from Arch repos

  • Matplotlib 3.1.2 from pip

Activity

  1. dstansby commented on Apr 21, 2020

    @dstansby
    Member

    I can bisect this back to b03370a from #13642

  2. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    I can't reproduce this, neither on master, nor in 3.2.1.

    Its hard to see why #13642 would have any effect if there were subplots or not since the scaling is independent in each axes, so I'm a little skeptical of the bisect.

    Are both of you using a clean matplotlibrc? Maybe there is something in there that has a bad interaction?

    Can anyone else reproduce this?

    Does it happen with plot?

  3. dstansby commented on Apr 21, 2020

    @dstansby
    Member

    I'm using the macosx backend, and as far as I know a clean matplotlibrc.

  4. QuLogic commented on Apr 21, 2020

    @QuLogic
    Member

    I can reproduce with TkAgg as well, and that's the only thing set in my matplotlibrc.

  5. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    which python and numpy? I'm using

    python                    3.7.6
    numpy                     1.17.5
    
  6. dstansby commented on Apr 21, 2020

    @dstansby
    Member

    I'm 3.7.7 and 1.18.1

  7. QuLogic commented on Apr 21, 2020

    @QuLogic
    Member

    My environment is always as old as possible, Python 3.6.8 and NumPy 1.15.0

  8. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    Well, I can't reproduce, so I can't really help debug. Just upped to 3.8.2 and numpy 1.18.2 and it still works fine for me. Qt5Agg and macosx.

  9. dstansby commented on Apr 21, 2020

    @dstansby
    Member

    This doesn't happen with plot for me (the single point doesn't show up, but the axes are autoscaled properly). I can also slim it down to a very simple example below, and the same issue persists.

    import matplotlib.pyplot as plt
    
    fig, axs = plt.subplots(1, 2)
    for ax in axs:
        ax.scatter(0, 0)
    
    plt.show()
  10. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    I can reproduce if I use a base environment installed directly from conda. But I cannot reproduce in my dev environment.

  11. ImportanceOfBeingErnest commented on Apr 21, 2020

    @ImportanceOfBeingErnest
    Member

    I can also reproduce in master with Python 3.6.4, numpy Python 1.16.2 with Qt5Agg backend, no changes to rc file - which is a conda environment with matplotlib development version installed on top.

    In case you want to look for differences, this is my `conda list` output:
    # Name                    Version                   Build  Channel
    alabaster                 0.7.12                   py36_0
    asn1crypto                0.24.0                   py36_0
    astroid                   1.6.2                    py36_0
    atomicwrites              1.2.1                    py36_0
    attrs                     17.4.0                   py36_0
    babel                     2.6.0                    py36_0
    blas                      1.0                         mkl
    bleach                    2.1.3                    py36_0
    ca-certificates           2019.1.23                     0
    cairo                     1.14.12              hf171d8a_3
    certifi                   2019.3.9                 py36_0
    cffi                      1.12.2           py36h7a1dbc1_1
    chardet                   3.0.4                    py36_1
    cloudpickle               0.5.2                    py36_1
    colorama                  0.4.1                    py36_0
    colorspacious             1.1.2                    pypi_0    pypi
    coverage                  4.5.1            py36hfa6e2cd_0
    cryptography              2.6.1            py36h7a1dbc1_0
    cycler                    0.10.0           py36h009560c_0
    decorator                 4.2.1                    py36_0
    docutils                  0.14             py36h6012d8f_0
    entrypoints               0.3                      pypi_0    pypi
    execnet                   1.3.0                    py36_1    https://repo.continuum.io/pkgs/free
    flake8                    3.7.8                    pypi_0    pypi
    freetype                  2.9.1                ha9979f8_1
    html5lib                  1.0.1            py36h047fa9f_0
    icc_rt                    2019.0.0             h0cc432a_1
    icu                       58.2                 ha66f8fd_1
    idna                      2.8                      py36_0
    imagesize                 1.1.0                    py36_0
    intel-openmp              2018.0.0                      8
    ipykernel                 4.8.2                    py36_0
    ipython                   6.2.1            py36h9cf0123_1
    ipython_genutils          0.2.0            py36h3c5d0ee_0
    isort                     4.3.4                    py36_0
    jedi                      0.11.1                   py36_1
    jinja2                    2.10                     py36_0
    jpeg                      9b                   hb83a4c4_2
    jsonschema                2.6.0            py36h7636477_0
    jupyter_client            5.2.3                    py36_0
    jupyter_core              4.4.0            py36h56e9d50_0
    kiwisolver                1.0.1                    pypi_0    pypi
    lazy-object-proxy         1.3.1            py36hd1c21d2_0
    libpng                    1.6.36               h2a8f88b_0
    libtiff                   4.0.9                h0f13578_0
    markupsafe                1.1.1            py36he774522_0
    matplotlib                3.1.1+1937.g7c816c585           dev_0    <develop>
    mccabe                    0.6.1            py36hb41005a_1
    mistune                   0.8.3                    py36_0
    mkl                       2019.3                      203
    mkl_fft                   1.0.10           py36h14836fe_0
    mkl_random                1.0.2            py36h343c172_0
    mock                      2.0.0            py36h9086845_0
    more-itertools            4.1.0                    py36_0
    msinttypes                r26                  h7e1a5f4_2
    nbconvert                 5.3.1            py36h8dc0fde_0
    nbformat                  4.4.0            py36h3a5bc1b_0
    numpy                     1.16.2           py36h19fb1c0_0
    numpy-base                1.16.2           py36hc3f5095_0
    numpydoc                  0.8.0                    py36_0
    olefile                   0.46                     py36_0
    openssl                   1.1.1b               he774522_1
    packaging                 19.0                     py36_0
    pandas                    0.24.1           py36ha925a31_0
    pandoc                    1.19.2.1             hb2460c7_1
    pandocfilters             1.4.2            py36h3ef6317_1
    parso                     0.1.1            py36hae3edee_0
    patsy                     0.5.0                    py36_0
    pbr                       4.0.0                    py36_0
    pep8                      1.7.1                    py36_0
    pickleshare               0.7.4            py36h9de030f_0
    pillow                    5.4.1            py36hdc69c19_0
    pip                       10.0.0.dev0              pypi_0    pypi
    pixman                    0.34.0               hcef7cb0_3
    pluggy                    0.6.0            py36hc7daf1e_0
    prompt_toolkit            1.0.15           py36h60b8f86_0
    psutil                    5.4.3            py36hfa6e2cd_0
    py                        1.5.3                    py36_0
    pycairo                   1.17.1           py36h511c3a9_0
    pycodestyle               2.5.0                    pypi_0    pypi
    pycparser                 2.19                     py36_0
    pyflakes                  2.1.1                    pypi_0    pypi
    pygments                  2.3.1                    py36_0
    pylint                    1.8.3                    py36_0
    pyopenssl                 19.0.0                   py36_0
    pyparsing                 2.3.1                    py36_0
    pyqt                      5.9.2            py36h6538335_2
    pysocks                   1.6.8                    py36_0
    pytest                    3.6.4                    py36_0
    pytest-cache              1.0                      pypi_0    pypi
    pytest-cov                2.5.1            py36h6ab2a5a_0
    pytest-flake8             1.0.4                    pypi_0    pypi
    pytest-pep8               1.0.6                    pypi_0    pypi
    python                    3.6.4                h0c2934d_3
    python-dateutil           2.8.0                    py36_0
    pytz                      2018.9                   py36_0
    pyzmq                     17.0.0           py36hfa6e2cd_0
    qt                        5.9.7            vc14h73c81de_0
    qtawesome                 0.4.4            py36h5aa48f6_0
    qtconsole                 4.3.1            py36h99a29a9_0
    qtpy                      1.4.0                    py36_0
    requests                  2.21.0                   py36_0
    rope                      0.10.7           py36had63a69_0
    scipy                     1.0.0            py36h1260518_0
    seaborn                   0.9.0                    py36_0
    setuptools                40.8.0                   py36_0
    simplegeneric             0.8.1                    py36_2
    sip                       4.19.8           py36h6538335_0
    six                       1.12.0                   py36_0
    snowballstemmer           1.2.1            py36h763602f_0
    sphinx                    1.8.1                    pypi_0    pypi
    sphinx-copybutton         0.2.5                    pypi_0    pypi
    sphinx-gallery            0.5.0.dev0                dev_0    <develop>
    sphinxcontrib             1.0                      py36_1
    sphinxcontrib-websupport  1.1.0                    py36_1
    spyder                    3.2.8                    py36_0
    sqlite                    3.26.0               he774522_0
    statsmodels               0.9.0            py36h452e1ab_0
    testpath                  0.3.1            py36h2698cfe_0
    tk                        8.6.8                hfa6e2cd_0
    tornado                   6.0.2            py36he774522_0
    traitlets                 4.3.2            py36h096827d_0
    typing                    3.6.4                    py36_0
    urllib3                   1.24.1                   py36_0
    vc                        14.1                 h0510ff6_4
    vs2015_runtime            14.15.26706          h3a45250_0
    wcwidth                   0.1.7            py36h3d5aa90_0
    webencodings              0.5.1            py36h67c50ae_1
    wheel                     0.33.1                   py36_0
    win_inet_pton             1.1.0                    py36_0
    wincertstore              0.2              py36h7fe50ca_0
    wrapt                     1.10.11          py36he5f5981_0
    zlib                      1.2.11               h62dcd97_3
    
  12. added this to the v3.2.2 milestone on Apr 21, 2020
  13. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    OK, this is some sort of round off error. pp.get_datalim(ax.transData) gives Bbox(x0=0.0, y0=2.7755575615628914e-17, x1=0.0, y1=2.7755575615628914e-17) in my conda env and
    Bbox(x0=0.0, y0=0.0, x1=0.0, y1=0.0) in my development env.

  14. jklymak commented on Apr 21, 2020

    @jklymak
    Member
    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    
    fig, axs = plt.subplots(1, 1)
    for ax in [axs]:
        pp = ax.scatter([0.0], [0.0])  #, 'd', markersize=10)
        transOffset = pp.get_offset_transform()
        off = (transOffset.get_affine() + ax.transData.inverted()).transform([[0.0, 0.0]])
        print('off2', off)

    yields on my pure conda env:

    off2 [[0.00000000e+00 2.77555756e-17]]
    

    On my dev env:

    off2 [[0. 0.]]
    
  15. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    narrowing down further:

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(1, 1)
    off = (ax.transData.inverted()).transform([[0.0, 0.0]])
    print('offset', off[0][1]+0.14285714285714288)
    

    pure conda:

    offset 2.7755575615628914e-17
    

    My dev env:

    offset 0.0
    
  16. jklymak commented on Apr 21, 2020

    @jklymak
    Member

    So, to me, the fundamental problem is just choosing the data lim in the face of y0 = y1

  17. kannes commented on Apr 27, 2020

    @kannes
    Author

    This overwhelming and quick response was totally unexpected. Thank you guys so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions