示例#1
0
def test_pcolorimage_setdata():
    ax = plt.gca()
    im = PcolorImage(ax)
    x = np.arange(3, dtype=np.float64)
    y = np.arange(4, dtype=np.float64)
    z = np.arange(6, dtype=np.float64).reshape((3, 2))
    im.set_data(x, y, z)
    x[0] = y[0] = z[0, 0] = 9.9
    assert im._A[0, 0] == im._Ax[0] == im._Ay[0] == 0, 'value changed'
示例#2
0
def test_pcolorimage_setdata():
    ax = plt.gca()
    im = PcolorImage(ax)
    x = np.arange(3, dtype=float)
    y = np.arange(4, dtype=float)
    z = np.arange(6, dtype=float).reshape((3, 2))
    im.set_data(x, y, z)
    x[0] = y[0] = z[0, 0] = 9.9
    assert im._A[0, 0] == im._Ax[0] == im._Ay[0] == 0, 'value changed'
示例#3
0
def pcolorimage(ax, x=None, y=None, A=None, **kwargs):
    img = PcolorImage(ax, x, y, A, **kwargs)
    img.set_extent([x[0], x[-1], y[0],
                    y[-1]])  # Have to add this or the fig won't save...
    ax.images.append(img)
    ax.set_xlim(left=x[0], right=x[-1])
    ax.set_ylim(bottom=y[0], top=y[-1])
    ax.autoscale_view(tight=True)
    return img, ax
示例#4
0
def pcolorimage(ax, x=None, y=None, A=None, **kwargs):
    img = PcolorImage(ax, x, y, A, **kwargs)
    ax.images.append(img)
    ax.set_xlim(left=x[0], right=x[-1])
    ax.set_ylim(bottom=y[0], top=y[-1])
    ax.autoscale_view(tight=True)
    return img
示例#5
0
def pcolorimage(ax, x, y, Z):
    """
    Make a PcolorImage based on Z = (x, y, 4) [byte] array

    This is to fix an omission ('bug') in the current (as of this
    writing) version of MatPlotLib.  I may become superfluous in the
    future.
    """
    img = PcolorImage(ax, x, y, Z)
    ax.images.append(img)
    xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
    ax.update_datalim(np.array([[xl, yb], [xr, yt]]))
    ax.autoscale_view(tight=True)
    return img
示例#6
0
def test(n = None):
    N = 1000
    x = np.exp(np.linspace(-2.0, 3.0, N))
    y = np.exp(np.linspace(-2.0, 2.0, N))
    x = (np.linspace(-2.0, 3.0, N))
    y = (np.linspace(-2.0, 2.0, N))

    X, Y = np.meshgrid(x, y)
    X1 = 0.5*(X[:-1,:-1] + X[1:,1:])
    Y1 = 0.5*(Y[:-1,:-1] + Y[1:,1:])

    Z1 = bivariate_normal(X1, Y1, 0.1, 0.2, 1.27, 1.11) + 100.*bivariate_normal(X1, Y1, 1.0, 1.0, 0.23, 0.72)
    Z1[Z1>0.9*np.max(Z1)] = +np.inf

    ZR = bivariate_normal(X1, Y1, 0.1, 0.2, 1.27, 1.11) + 100.*bivariate_normal(X1, Y1, 1.0, 1.0, 0.23, 0.72)
    ZG = bivariate_normal(X1, Y1, 0.1, 0.2, 2.27, 0.11) + 100.*bivariate_normal(X1, Y1, 1.0, 1.0, 0.43, 0.52)
    ZB = bivariate_normal(X1, Y1, 0.1, 0.2, 0.27, 2.11) + 100.*bivariate_normal(X1, Y1, 1.0, 1.0, 0.53, 0.92)
    ZA = bivariate_normal(X1, Y1, 0.1, 0.2, 3.27,-1.11) + 100.*bivariate_normal(X1, Y1, 1.0, 1.0, 0.23, 0.82)

    Z = np.ndarray(ZR.shape + (4,))
    Z[...,0] = ZR /ZR.max()
    Z[...,1] = ZG /ZG.max()
    Z[...,2] = ZB /ZB.max()
    Z[...,3] = np.exp(-ZA /ZA.max())


    Z = (Z*255).astype(np.uint8)


    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)

    #col = plt.get_cmap('terrain_r')
    #col = get_cfunc('RGBWaves200') # need to define first, use colormap instaed
    #col = plt.get_cmap('gnuplot2')
    #col = colormap('cubehelix')
    #col = colormap('autumn')
    #col = colormap('jet')
    #col = colormap('RGBWaves', 100)
    #col = ColorBWC(mode=0)
    #col = colormap('viridis')
    col = colormap('cividis')
    #col = ColorBlindRainbow()
    #col = ColorGray()
    #col = ColorGray(gamma=(3,1,2))
    #col = IsoColorDivergeBR()
    #col = ColorMapList(['Orange', 'Gold', 'Salmon', 'Tomato', 255], gamma = 2)
    #col = ColorSolid(.5)
    #col = ColorJoin((ColorGray(.5), BlendInFilter(ColorBlindRainbow(gamma = .5), frac=0.25)), .3)
    #col = ColorJoin((ColorGray(-.5), BlendInFilter(ColorBlindRainbow(gamma = .5), frac=-0.25), IsoColorDivergeBR()), blend=(.5,.1))
    #col = ColorJoin((ColorGray(.5), ColorBlindRainbow(gamma = .5), 'green'), blend = 0.1, method = 'linear')
    #col = ColorBlindRainbow(gamma = .5)
    #col = FilterColorBlindRed(IsoColors('BlindRainbow', 9))
    #col = IsoColorDivergeBWR(n)
    #col = IsoColorRainbow15()
    #col = FilterColorGray(IsoColorRainbow21())
    #col = IsoColorLights('BlindRainbow')
    #col = IsoColorRainbow(6)
    #col = ColorBlend((BlendInFilter(ColorBlindRainbow(gamma = .5), frac=0.25), ColorGray(.5)))
    #col = ColorBlendBspline((ColorGray(.5), WaveFilter(ColorBlindRainbow(), nwaves = 20)),)
    #col = ColorBlend((ColorMapList(['Green']), ColorMapList(['Red'])))
    #col = ColorBlendBspline(('red', 'green', 'yellow', 'blue'), k=2)
    #col = ColorDiverging(('#D00000','#808080','#0000D0'))
    #col = ColorCircle(func = lambda x: x**10)
    #col = ColorCircle(model = 'HCL', init = [0, 1, .5])
    #col = ColorCircle(model = 'LChuv', init = [100, 100, .5])
    #col = get_cmap('autumn')
    #col = ColorBlend((ColorGray(reverse=False), HueRotateFilter(ColorBlendWave('Gold', 'Purple', nwaves = 20), angle = 180)))
    #col = ShadeColor(gamma=1/2.2)
    #col = ShadeColor(gamma=1, model='RGB')

    #input filter
    #col = ColorScale(col, lambda x : (np.log((x)+1)/(np.exp(-3)-1))
    #col = ColorScaleGamma(col, -1/2.2)
    #col = ColorScaleExp(col, 3)
    #col = ColorScaleLog(col, 3)

    # levels
    #col = IsoColors(col, 12)

    # COLOR FILTERS
    #col = FilterColorGray(col)
    #col = WaveFilter(col, nwaves = 20, property = 'H')
    #col = WaveFilter(col, nwaves = 20, property = 'I', model = 'YIQ')
    #col = WaveFilter(col, nwaves = 20, index = 2, method = 2, model = 'LChuv')
    #col = WaveFilter(col, nwaves = 20, index = 0, method = 0, model = 'LChuv')
    #col = WaveFilter(col, nwaves = 20, property = 'V', model = 'HSV')
    #col = WaveFilter(col, nwaves = 20, property = 'S', model = 'HSV')
    #col = WaveFilter(col, nwaves = 20, property = 'C', model = 'CMY')
    #col = WaveFilter(col, nwaves = 20)
    #col = BlendInFilter(col, frac=-0.5)
    #col = FilterColorModel(col, model = 'sRGB')
    #col = Reverse(col) # why does it invert neg inf when used with WaveFilter?
    #col = FilterColorInvert(col)
    #col = FilterColorHueRotate(col, model = 'HCL', angle = 60)
    #col = FilterColorGamma(col, gamma = (1,2,3,4))
    #col = AlphaFilter(col, func = lambda x: 0.5*(1+np.sin(100*x)))
    #col = AlphaFilter(col, func = lambda x: x**2)
    #col = FuncBackgroundFilter(col, func = lambda x: x**2)
    #col = FuncBackgroundFilter(col, func = lambda x: 1 -2*np.abs(x-0.5))
    #col = ColorFilterColor(col, color = 'Pink')
    #col = HueRotateFilter(col, func = lambda x: 0.5 * np.sin(40*np.pi*x))
    #col = ColorFilterColor(col, color = 'Pink', reverse = True, method = 'min', clip = False)
    #col = ColorXFilterColor(col, color = 'Pink', reverse = False, method = 'vec')
    #col = ColorBlendBspline(('red','green','Gold','blue', ColorScale(col, lambda x: x*5-4)), k=2)
    #col = ComponentFilter(col, func = lambda x : 1-x**2)
    #col = FilterColorTransparent(col, transparent = ('#00007f', '#7f7fff'))
    #col = SetBackgroundFilter(col, background = '#FF0000')
    #col = FilterColorGraysRGB(col)

    # YFILTERS
    #Z2 = (x[1:] + x[-1])[None, :] * (y[1:] + y[-1])[:, None]
    #Z2 /= np.max(Z2)
    #col = FuncAlphaYFilter(col, data=Z2)


    # TEST INVERSE
    # model = 'Luv'
    # col = FilterColorModel(col, model = color_model(model).inverse())
    # col = FilterColorModel(col, model = color_model(model))


    # VISION IMPARED COLOR FILTERS
    #col = FilterColorBlindRed(col)
    #col = FilterVisCheck(col, 'tritanope')
    #col = FilterColorBlindness(col, 'achroma')
    #col = FilterColorBlindness(col, 'protan')
    #col = FilterColorBlindness(col, 'tritan')
    #col = FilterColorBlindness(col, 'deutan')


    #i = ax.pcolorfast(x, y, Z1, cmap = col, alpha=1.)
    #i = ax.pcolorfast(x, y, Z1, cmap = col)
    #Z1 = col(Z1, bytes = True)
    #i = pcolorimage(ax, x, y, Z1)

    # from matplotlib.image import PcolorImage
    i = PcolorImage(ax, x, y, Z)
    ax.images.append(i)
    # xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
    # ax.update_datalim(np.array([[xl, yb], [xr, yt]]))
    # ax.autoscale_view(tight=True)
    plt.colorbar(i)
    plt.show()
    return i