Skip to content

Instantly share code, notes, and snippets.

@mandli
Created March 23, 2014 16:33
Show Gist options
  • Save mandli/9725622 to your computer and use it in GitHub Desktop.
Save mandli/9725622 to your computer and use it in GitHub Desktop.
`__add__` colorbar functionality with break control
def add(colormaps, break_location=0.5):
lhs_dict = colormaps[0]._segmentdata
rhs_dict = colormaps[1]._segmentdata
new_dict = dict(red=[], green=[], blue=[])
# Scale rhs by half
for key in rhs_dict:
val_list = rhs_dict[key]
print(key, val_list)
for val in val_list:
new_dict[key].append((val[0] * break_location, val[1], val[2]))
# Append lhs
for key in lhs_dict:
val_list = lhs_dict[key]
print(key, val_list)
for val in val_list:
new_dict[key].append((break_location + val[0] * (1.0 - break_location), val[1], val[2]))
N = 256
gamma = 1.0
return colors.LinearSegmentedColormap('something', new_dict, N, gamma)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment