Skip to content

Severe bug in imshow when plotting images with small values #6394

Closed

Description

@astrofrog

The following minimal example:

import matplotlib
matplotlib.use('Agg')
from astropy.wcs import WCS
from wcsaxes import datasets
import matplotlib.pyplot as plt
hdu = datasets.fetch_msx_hdu()
plt.imshow(hdu.data, vmin=-2e-4, vmax=2e-4)
plt.savefig('image.png')

produces the following output:

image

This appears to be related to the fact the values in the image data are < 1. If I multiply all the values by 1e6, I get something sensible:

plt.imshow(hdu.data * 1e6, vmin=-2e-4, vmax=2e-4)
plt.savefig('image.png')

image

Activity

  1. tacaswell commented on May 10, 2016

    @tacaswell
    Member

    attn @mdboom

    It looks like this is master or 2.x?

  2. added this to the milestone on May 10, 2016
  3. astrofrog commented on May 10, 2016

    @astrofrog
    ContributorAuthor

    @tacaswell - this is on master (haven't tested on other branches)

  4. WeatherGod commented on May 10, 2016

    @WeatherGod
    Member

    What is the dtype of the input data? What is its range? I wonder if
    something degenerate is happening during normalization.

    Also, which version of matplotlib are you using? The master branch has a
    completely overhauled image architecture that may or may not suffer from
    this.

    On Tue, May 10, 2016 at 9:48 AM, Thomas Robitaille <notifications@github.com

    wrote:

    The following minimal example:

    import matplotlib
    matplotlib.use('Agg')
    from astropy.wcs import WCS
    from wcsaxes import datasets
    import matplotlib.pyplot as plt
    hdu = datasets.fetch_msx_hdu()
    plt.imshow(hdu.data, vmin=-2e-4, vmax=2e-4)
    plt.savefig('image.png')

    produces the following output:

    [image: image]
    https://cloud.githubusercontent.com/assets/314716/15148599/dedc6636-16bd-11e6-83f8-a06d4c5f5757.png

    This appears to be related to the fact the values in the image data are <

    1. If I multiply all the values by 1e6, I get something sensible:

    plt.imshow(hdu.data * 1e6, vmin=-2e-4, vmax=2e-4)
    plt.savefig('image.png')

    [image: image]
    https://cloud.githubusercontent.com/assets/314716/15148648/26fd7162-16be-11e6-84b9-347e388d99f2.png

    —
    You are receiving this because you are subscribed to this thread.
    Reply to this email directly or view it on GitHub
    #6394

  5. astrofrog commented on May 10, 2016

    @astrofrog
    ContributorAuthor

    @WeatherGod - the data is dtype('>f8'), so could be a big-endian issue? (this will be the case for a large fraction of Astronomical data). I am using the latest commit from master.

  6. jenshnielsen commented on May 10, 2016

    @jenshnielsen
    Member

    I can reproduce it with 2.x and master but not on 1.5.1 so it's likely to be a result of the image refactoring

    The following warning is also raised on 2.x/master

    /Users/jhn/Envs/mpl2x/lib/python3.5/site-packages/matplotlib/colors.py:435: RuntimeWarning: overflow encountered in multiply
      xa *= self.N
  7. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on May 10, 2016
  8. tacaswell commented on May 12, 2016

    @tacaswell
    Member

    It is something funny with the '>f8' type. If you do anything to change the data type of the input (multiply by 1, hdu.data.astype('float'), hdu.data.byteswap().newbyteorder()) fixes the plot.

    @mdboom I think the problem is in here https://github.com/matplotlib/matplotlib/blob/master/src/_image_wrapper.cpp#L280 which does not do anything special about non-native byte order. I am not sure of the right place to fix this (c++ layer or where we intake the data).

  9. efiring commented on May 15, 2016

    @efiring
    Member

    This should be fixed by #6422. Please reopen if you find this is not the case.

  10. added 2 commits that reference this issue on Jul 2, 2016
    6f4dbf8
    9d43cdb
  11. self-assigned this
    on Jul 2, 2016
  12. added 2 commits that reference this issue on Jul 2, 2016
    2b8f4d3
    e077c13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions