示例#1
0
def planck_cmap(ncolors=256):
    """
    Returns a color map similar to the one used for the "Planck CMB Map".
    Parameters
    ----------
    ncolors : int, *optional*
    Number of color segments (default: 256).
    Returns
    -------
    cmap : matplotlib.colors.LinearSegmentedColormap instance
    Linear segmented color map.
    """
    segmentdata = {
        "red": [(0.0, 0.00, 0.00), (0.1, 0.00, 0.00), (0.2, 0.00, 0.00),
                (0.3, 0.00, 0.00), (0.4, 0.00, 0.00), (0.5, 1.00, 1.00),
                (0.6, 1.00, 1.00), (0.7, 1.00, 1.00), (0.8, 0.83, 0.83),
                (0.9, 0.67, 0.67), (1.0, 0.50, 0.50)],
        "green": [(0.0, 0.00, 0.00), (0.1, 0.00, 0.00), (0.2, 0.00, 0.00),
                  (0.3, 0.30, 0.30), (0.4, 0.70, 0.70), (0.5, 1.00, 1.00),
                  (0.6, 0.70, 0.70), (0.7, 0.30, 0.30), (0.8, 0.00, 0.00),
                  (0.9, 0.00, 0.00), (1.0, 0.00, 0.00)],
        "blue": [(0.0, 0.50, 0.50), (0.1, 0.67, 0.67), (0.2, 0.83, 0.83),
                 (0.3, 1.00, 1.00), (0.4, 1.00, 1.00), (0.5, 1.00, 1.00),
                 (0.6, 0.00, 0.00), (0.7, 0.00, 0.00), (0.8, 0.00, 0.00),
                 (0.9, 0.00, 0.00), (1.0, 0.00, 0.00)]
    }
    return cm("Planck-like", segmentdata, N=int(ncolors), gamma=1.0)
示例#2
0
    def he(ncolors=256):
        """
            Returns a color map often used in High Energy Astronomy.

            Parameters
            ----------
            ncolors : int, *optional*
                Number of color segments (default: 256).

            Returns
            -------
            cmap : matplotlib.colors.LinearSegmentedColormap instance
                Linear segmented color map.

        """
        segmentdata = {"red":   [(0.000, 0.0, 0.0), (0.167, 0.0, 0.0),
                                 (0.333, 0.5, 0.5), (0.500, 1.0, 1.0),
                                 (0.667, 1.0, 1.0), (0.833, 1.0, 1.0),
                                 (1.000, 1.0, 1.0)],
                       "green": [(0.000, 0.0, 0.0), (0.167, 0.0, 0.0),
                                 (0.333, 0.0, 0.0), (0.500, 0.0, 0.0),
                                 (0.667, 0.5, 0.5), (0.833, 1.0, 1.0),
                                 (1.000, 1.0, 1.0)],
                       "blue":  [(0.000, 0.0, 0.0), (0.167, 1.0, 1.0),
                                 (0.333, 0.5, 0.5), (0.500, 0.0, 0.0),
                                 (0.667, 0.0, 0.0), (0.833, 0.0, 0.0),
                                 (1.000, 1.0, 1.0)]}

        return cm("High Energy", segmentdata, N=int(ncolors), gamma=1.0)
示例#3
0
def planck(ncolors=256):
    from matplotlib.colors import LinearSegmentedColormap as cm
    """
        Returns a color map similar to the one used for the "Planck CMB Map".
        Parameters
        ----------
        ncolors : int, *optional*
            Number of color segments (default: 256).
        Returns
        -------
        cmap : matplotlib.colors.LinearSegmentedColormap instance
            Linear segmented color map.
    """
    segmentdata = {"red":   [(0.0, 0.00, 0.00), (0.1, 0.00, 0.00),
                             (0.2, 0.00, 0.00), (0.3, 0.00, 0.00),
                             (0.4, 0.00, 0.00), (0.5, 1.00, 1.00),
                             (0.6, 1.00, 1.00), (0.7, 1.00, 1.00),
                             (0.8, 0.83, 0.83), (0.9, 0.67, 0.67),
                             (1.0, 0.50, 0.50)],
                   "green": [(0.0, 0.00, 0.00), (0.1, 0.00, 0.00),
                             (0.2, 0.00, 0.00), (0.3, 0.30, 0.30),
                             (0.4, 0.70, 0.70), (0.5, 1.00, 1.00),
                             (0.6, 0.70, 0.70), (0.7, 0.30, 0.30),
                             (0.8, 0.00, 0.00), (0.9, 0.00, 0.00),
                             (1.0, 0.00, 0.00)],
                   "blue":  [(0.0, 0.50, 0.50), (0.1, 0.67, 0.67),
                             (0.2, 0.83, 0.83), (0.3, 1.00, 1.00),
                             (0.4, 1.00, 1.00), (0.5, 1.00, 1.00),
                             (0.6, 0.00, 0.00), (0.7, 0.00, 0.00),
                             (0.8, 0.00, 0.00), (0.9, 0.00, 0.00),
                             (1.0, 0.00, 0.00)]}

    return cm("Planck-like", segmentdata, N=int(ncolors), gamma=1.0)
示例#4
0
    def pm(ncolors=256):
        """
            Returns a color map useful for a zero-centerd range of values.

            Parameters
            ----------
            ncolors : int, *optional*
                Number of color segments (default: 256).

            Returns
            -------
            cmap : matplotlib.colors.LinearSegmentedColormap instance
                Linear segmented color map.

        """
        segmentdata = {"red":   [(0.0, 1.00, 1.00), (0.1, 0.96, 0.96),
                                 (0.2, 0.84, 0.84), (0.3, 0.64, 0.64),
                                 (0.4, 0.36, 0.36), (0.5, 0.00, 0.00),
                                 (0.6, 0.00, 0.00), (0.7, 0.00, 0.00),
                                 (0.8, 0.00, 0.00), (0.9, 0.00, 0.00),
                                 (1.0, 0.00, 0.00)],
                       "green": [(0.0, 0.50, 0.50), (0.1, 0.32, 0.32),
                                 (0.2, 0.18, 0.18), (0.3, 0.08, 0.08),
                                 (0.4, 0.02, 0.02), (0.5, 0.00, 0.00),
                                 (0.6, 0.02, 0.02), (0.7, 0.08, 0.08),
                                 (0.8, 0.18, 0.18), (0.9, 0.32, 0.32),
                                 (1.0, 0.50, 0.50)],
                       "blue":  [(0.0, 0.00, 0.00), (0.1, 0.00, 0.00),
                                 (0.2, 0.00, 0.00), (0.3, 0.00, 0.00),
                                 (0.4, 0.00, 0.00), (0.5, 0.00, 0.00),
                                 (0.6, 0.36, 0.36), (0.7, 0.64, 0.64),
                                 (0.8, 0.84, 0.84), (0.9, 0.96, 0.96),
                                 (1.0, 1.00, 1.00)]}

        return cm("Plus Minus", segmentdata, N=int(ncolors), gamma=1.0)
示例#5
0
    def he(ncolors=256):
        """
            Returns a color map often used in High Energy Astronomy.

            Parameters
            ----------
            ncolors : int, *optional*
                Number of color segments (default: 256).

            Returns
            -------
            cmap : matplotlib.colors.LinearSegmentedColormap instance
                Linear segmented color map.

        """
        segmentdata = {
            "red": [(0.000, 0.0, 0.0), (0.167, 0.0, 0.0), (0.333, 0.5, 0.5),
                    (0.500, 1.0, 1.0), (0.667, 1.0, 1.0), (0.833, 1.0, 1.0),
                    (1.000, 1.0, 1.0)],
            "green": [(0.000, 0.0, 0.0), (0.167, 0.0, 0.0), (0.333, 0.0, 0.0),
                      (0.500, 0.0, 0.0), (0.667, 0.5, 0.5), (0.833, 1.0, 1.0),
                      (1.000, 1.0, 1.0)],
            "blue": [(0.000, 0.0, 0.0), (0.167, 1.0, 1.0), (0.333, 0.5, 0.5),
                     (0.500, 0.0, 0.0), (0.667, 0.0, 0.0), (0.833, 0.0, 0.0),
                     (1.000, 1.0, 1.0)]
        }

        return cm("High Energy", segmentdata, N=int(ncolors), gamma=1.0)
示例#6
0
    def pm(ncolors=256):
        """
            Returns a color map useful for a zero-centerd range of values.

            Parameters
            ----------
            ncolors : int, *optional*
                Number of color segments (default: 256).

            Returns
            -------
            cmap : matplotlib.colors.LinearSegmentedColormap instance
                Linear segmented color map.

        """
        segmentdata = {
            "red": [(0.0, 1.00, 1.00), (0.1, 0.96, 0.96), (0.2, 0.84, 0.84),
                    (0.3, 0.64, 0.64), (0.4, 0.36, 0.36), (0.5, 0.00, 0.00),
                    (0.6, 0.00, 0.00), (0.7, 0.00, 0.00), (0.8, 0.00, 0.00),
                    (0.9, 0.00, 0.00), (1.0, 0.00, 0.00)],
            "green": [(0.0, 0.50, 0.50), (0.1, 0.32, 0.32), (0.2, 0.18, 0.18),
                      (0.3, 0.08, 0.08), (0.4, 0.02, 0.02), (0.5, 0.00, 0.00),
                      (0.6, 0.02, 0.02), (0.7, 0.08, 0.08), (0.8, 0.18, 0.18),
                      (0.9, 0.32, 0.32), (1.0, 0.50, 0.50)],
            "blue": [(0.0, 0.00, 0.00), (0.1, 0.00, 0.00), (0.2, 0.00, 0.00),
                     (0.3, 0.00, 0.00), (0.4, 0.00, 0.00), (0.5, 0.00, 0.00),
                     (0.6, 0.36, 0.36), (0.7, 0.64, 0.64), (0.8, 0.84, 0.84),
                     (0.9, 0.96, 0.96), (1.0, 1.00, 1.00)]
        }

        return cm("Plus Minus", segmentdata, N=int(ncolors), gamma=1.0)
示例#7
0
def plot_array_pil(x,
                   pil_object=True,
                   lims=None,
                   log_input=False,
                   log_clip=1e-7):

    norm_x = np.squeeze(x)

    cm = planck_cmap()
    plt.register_cmap(cmap=cm)

    img = Image.fromarray(cm(norm_x, bytes=True))

    if pil_object:
        return img
    else:
        return np.array(img)
示例#8
0
    def fu(ncolors=256):
        """
            Returns a color map used for the "Faraday Map Uncertainty".

            Parameters
            ----------
            ncolors : int, *optional*
                Number of color segments (default: 256).

            Returns
            -------
            cmap : matplotlib.colors.LinearSegmentedColormap instance
                Linear segmented color map.

            References
            ----------
            .. [#] N. Opermann et. al.,
                "An improved map of the Galactic Faraday sky",
                Astronomy & Astrophysics, Volume 542, id.A93, 06/2012;
                `arXiv:1111.6186 <http://www.arxiv.org/abs/1111.6186>`_

        """
        segmentdata = {
            "red": [(0.000, 1.00, 1.00), (0.100, 0.80, 0.80),
                    (0.200, 0.65, 0.65), (0.410, 0.60, 0.60),
                    (0.500, 0.70, 0.70), (0.560, 0.96, 0.96),
                    (0.590, 1.00, 1.00), (0.740, 0.80, 0.80),
                    (0.800, 0.80, 0.80), (0.900, 0.50, 0.50),
                    (1.000, 0.40, 0.40)],
            "green": [(0.000, 0.90, 0.90), (0.200, 0.65, 0.65),
                      (0.362, 0.95, 0.95), (0.500, 1.00, 1.00),
                      (0.638, 0.88, 0.88), (0.800, 0.25, 0.25),
                      (0.900, 0.30, 0.30), (1.000, 0.20, 0.20)],
            "blue": [(0.000, 1.00, 1.00), (0.100, 0.80, 0.80),
                     (0.200, 1.00, 1.00), (0.410, 1.00, 1.00),
                     (0.440, 0.96, 0.96), (0.500, 0.70, 0.70),
                     (0.590, 0.42, 0.42), (0.800, 0.00, 0.00),
                     (1.000, 0.00, 0.00)]
        }

        return cm("Faraday Uncertainty",
                  segmentdata,
                  N=int(ncolors),
                  gamma=1.0)
示例#9
0
    def fu(ncolors=256):
        """
            Returns a color map used for the "Faraday Map Uncertainty".

            Parameters
            ----------
            ncolors : int, *optional*
                Number of color segments (default: 256).

            Returns
            -------
            cmap : matplotlib.colors.LinearSegmentedColormap instance
                Linear segmented color map.

            References
            ----------
            .. [#] N. Opermann et. al.,
                "An improved map of the Galactic Faraday sky",
                Astronomy & Astrophysics, Volume 542, id.A93, 06/2012;
                `arXiv:1111.6186 <http://www.arxiv.org/abs/1111.6186>`_

        """
        segmentdata = {"red":   [(0.000, 1.00, 1.00), (0.100, 0.80, 0.80),
                                 (0.200, 0.65, 0.65), (0.410, 0.60, 0.60),
                                 (0.500, 0.70, 0.70), (0.560, 0.96, 0.96),
                                 (0.590, 1.00, 1.00), (0.740, 0.80, 0.80),
                                 (0.800, 0.80, 0.80), (0.900, 0.50, 0.50),
                                 (1.000, 0.40, 0.40)],
                       "green": [(0.000, 0.90, 0.90), (0.200, 0.65, 0.65),
                                 (0.362, 0.95, 0.95), (0.500, 1.00, 1.00),
                                 (0.638, 0.88, 0.88), (0.800, 0.25, 0.25),
                                 (0.900, 0.30, 0.30), (1.000, 0.20, 0.20)],
                       "blue":  [(0.000, 1.00, 1.00), (0.100, 0.80, 0.80),
                                 (0.200, 1.00, 1.00), (0.410, 1.00, 1.00),
                                 (0.440, 0.96, 0.96), (0.500, 0.70, 0.70),
                                 (0.590, 0.42, 0.42), (0.800, 0.00, 0.00),
                                 (1.000, 0.00, 0.00)]}

        return cm("Faraday Uncertainty", segmentdata, N=int(ncolors),
                  gamma=1.0)
示例#10
0
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap as cm
import numpy as np

arr = np.random.randint(0,2,size=(10,20)).reshape(10,20)

#fig = plt.figure(figsize=(4, 4))
im = plt.imshow(arr, interpolation='none', vmin = 0, vmax = 1, cmap = cm(['white','black']))
plt.colorbar(im, use_gridspec=True)
plt.show()