Skip to content

Instantly share code, notes, and snippets.

@peijunz peijunz/
Last active Oct 10, 2018

What would you like to do?
Normalize color by center and plot density plot in XoY way
from matplotlib.colors import Normalize
class CenterNorm(Normalize):
'''Demos see'''
def __init__(self, vc=0, cc=0.5, vmin=None, vmax=None, clip=False):
vc value of center
cc color of center
Normalize.__init__(self, vmin, vmax, clip)
assert 0< cc < 1, "Central color should be in (0, 1)" = vc = cc
def __call__(self, value, clip=None):
dv = np.array([ - self.vmin, self.vmax -])
dc = np.array([, 1 -])
k = 1/max(dv/dc)
import numpy as np
def imshow_xy(ax, x, y, z, *args, **argv):
'''x is x of xoy rhs system, i.e. j index of image
y is y of xoy rhs system, i.e. -i index of image
z is function of x, y, i.e. z[i, j]=f(x[i], y[j])
Image is actual image matrix, I[i, j]=z[-j, i]'''
assert z.shape == (len(x), len(y)), "Shape unmatched"
ex = np.mean(np.diff(x))/2
ey = np.mean(np.diff(y))/2
argv['extent'] = (x[0]-ex, x[-1]+ex, y[0]-ey, y[-1]+ey)
return ax.imshow((z.T)[::-1, :], *args, **argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.