Skip to main content
`Ctrl`+`K`

# SimpleNorm

class astropy.visualization.mpl_normalize.SimpleNorm(stretch='linear', percent=None, *, min_percent=None, max_percent=None, vmin=None, vmax=None, power=1.0, log_a=1000, asinh_a=0.1, sinh_a=0.3, clip=False, invalid=-1.0)

  Bases: `object`

  Class to create a normalization object that can be used for displaying images with Matplotlib.

  This convenience class provides the most common image stretching functions. Additional stretch functions are available in `ImageNormalize`.

  Parameters:
    stretch{‘linear’, ‘sqrt’, :ref: ‘power’, log’, ‘asinh’, ‘sinh’}, optional

      The stretch function to apply to the image. The default is ‘linear’.

    percent `python:float`, optional

      The percentage of the image values used to determine the pixel values of the minimum and maximum cut levels. The lower cut level will set at the `(100 - percent) / 2` percentile, while the upper cut level will be set at the `(100 + percent) / 2` percentile. The default is 100.0. `percent` is ignored if either `min_percent` or `max_percent` is input.

    min_percent `python:float`, optional

      The percentile value used to determine the pixel value of minimum cut level. The default is 0.0. `min_percent` overrides `percent`.

    max_percent `python:float`, optional

      The percentile value used to determine the pixel value of maximum cut level. The default is 100.0. `max_percent` overrides `percent`.

    vmin `python:float`, optional

      The pixel value of the minimum cut level. Data values less than `vmin` will set to `vmin` before stretching the image. The default is the image minimum. `vmin` overrides `min_percent`.

    vmax `python:float`, optional

      The pixel value of the maximum cut level. Data values greater than `vmax` will set to `vmax` before stretching the image. The default is the image maximum. `vmax` overrides `max_percent`.

    power `python:float`, optional

      The power index for `stretch='power'`. The default is 1.0.

    log_a `python:float`, optional

      The log index for `stretch='log'`. The default is 1000.

    asinh_a `python:float`, optional

      For `stretch='asinh'`, the value where the asinh curve transitions from linear to logarithmic behavior, expressed as a fraction of the normalized image. Must be in the range between 0 and 1. The default is 0.1.

    sinh_a `python:float`, optional

      The scaling parameter for `stretch='sinh'`. The default is 0.3.

    clip bool, optional

      If `True`, data values outside the [0:1] range are clipped to the [0:1] range.

    invalid `python:None` or `python:float`, optional

      Value to assign NaN values generated by the normalization. NaNs in the input `data` array are not changed. For matplotlib normalization, the `invalid` value should map to the matplotlib colormap “under” value (i.e., any finite value < 0). If `None`, then NaN values are not replaced. This keyword has no effect if `clip=True`.

  See also

  `simple_norm`

  Examples

      import numpy as np
      import matplotlib.pyplot as plt
      from astropy.visualization import SimpleNorm

      image = np.arange(65536).reshape((256, 256))
      snorm = SimpleNorm('sqrt', percent=98)
      norm = snorm(image)
      fig, ax = plt.subplots()
      axim = ax.imshow(image, norm=norm, origin='lower')
      fig.colorbar(axim)

  (`png`, `svg`, `pdf`)

  Methods Summary

  `__call__`(data) | Return an `ImageNormalize` instance that can be used for displaying images with Matplotlib.
  `imshow`(data[, ax]) | A convenience function to display an image using matplotlib's `matplotlib.pyplot.imshow` function with the normalization defined by this class.

  Methods Documentation

  __call__(data)

    Return an `ImageNormalize` instance that can be used for displaying images with Matplotlib.

    Parameters:
      data `ndarray`

        The image array.

    Returns:
      result `ImageNormalize` instance

        An `ImageNormalize` instance that can be used for displaying images with Matplotlib.

  imshow(data, ax=None, **kwargs)

    A convenience function to display an image using matplotlib’s `matplotlib.pyplot.imshow` function with the normalization defined by this class.

    Parameters:
      data 2D or 3D numpy:array_like

        The data to display. Can be whatever `imshow` and `ImageNormalize` both accept.

      ax `python:None` or `Axes`, optional

        The matplotlib axes on which to plot. If `None`, then the current `Axes` instance is used.

      **kwargs `python:dict`, optional

        Keywords arguments passed to `imshow`. Cannot include the `norm` or `X` keyword.

    Returns:
      result `AxesImage`

        The `AxesImage` generated by `imshow`.

    Examples

        import numpy as np
        import matplotlib.pyplot as plt
        from astropy.visualization import SimpleNorm

        image = np.arange(65536).reshape((256, 256))
        snorm = SimpleNorm('sqrt', percent=98)
        fig, ax = plt.subplots()
        axim = snorm.imshow(image, ax=ax, origin='lower')
        fig.colorbar(axim)

    (`png`, `svg`, `pdf`)