Skip to content

Instantly share code, notes, and snippets.

@endolith
Last active November 19, 2019 22:07
Show Gist options
  • Save endolith/f96d3939ffa5d79c81cc to your computer and use it in GitHub Desktop.
Save endolith/f96d3939ffa5d79c81cc to your computer and use it in GitHub Desktop.
scatter colormap example not exactly the same
from matplotlib.pyplot import scatter
import numpy as np
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [4, 3, 2, 1]
alpha = [0.2, 0.3, 0.8, 1.0]
c = np.asarray([(0, 0, 1, a) for a in alpha])
plt.subplot(2, 1, 1)
s = scatter(x, y, color=c, edgecolors=c)
plt.subplot(2, 1, 2)
cdict4 = {'red': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'green': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'blue': ((0.0, 0.0, 0.0),
(1.0, 1.0, 0.0)),
'alpha': ((0.0, 0.0, 0.0),
(1.0, 1.0, 0.0))
}
plt.register_cmap(name='BlueAlpha', data=cdict4)
scatter(x, y, c=alpha, edgecolors=alpha, vmin=0, vmax=1)
plt.set_cmap('BlueAlpha')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment