8000 Add PiecewiseLinearNorm by dopplershift · Pull Request #4666 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add PiecewiseLinearNorm #4666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed OffsetNorm.inverse method
This will allow the ticks of colors to be spaced as desired.
Also simplified the math per the brilliant @joferkington
http://stackoverflow.com/a/20146989/1552748
  • Loading branch information
phobson committed Jun 6, 2015
commit fd9e62480a52354bdfe20cc4ac2931ae963960cd
36 changes: 2 additions & 34 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,46 +1033,14 @@ def __call__(self, value, clip=None):
result = ma.array(np.clip(result.filled(vmax), vmin, vmax),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If clip is true, result is assigned here, but it's assigned again below.

mask=mask)

# ma division is very slow; we can take a shortcut
resdat = result.data

#First scale to -1 to 1 range, than to from 0 to 1.
resdat -= vcenter
resdat[resdat > 0] /= abs(vmax - vcenter)
resdat[resdat < 0] /= abs(vmin - vcenter)

resdat /= 2.
resdat += 0.5
result = np.ma.array(resdat, mask=result.mask, copy=False)
x, y = [vmin, vcenter, vmax], [0, 0.5, 1]
result = np.ma.masked_array(np.interp(value, x, y))

if is_scalar:
result = result[0]

return result

def inverse(self, value):
if not self.scaled():
raise ValueError("Not invertible until scaled")

vmin, vcenter, vmax = self.vmin, self.vcenter, self.vmax
vmin = float(self.vmin)
vcenter = float(self.vcenter)
vmax = float(self.vmax)

if cbook.iterable(value):
val = ma.asarray(value)
val = 2 * (val - 0.5)
val[val > 0] *= abs(vmax - vcenter)
val[val < 0] *= abs(vmin - vcenter)
val += vcenter
return val
else:
val = 2 * (val - 0.5)
if val < 0:
return val * abs(vmin - vcenter) + vcenter
else:
return val * abs(vmax - vcenter) + vcenter

def autoscale_None(self, A):
' autoscale only None-valued vmin or vmax'
if self.vmin is None and np.size(A) > 0:
Expand Down
0