Skip to content

Instantly share code, notes, and snippets.

@prerakmody
Created August 5, 2021 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prerakmody/aa3996f2d40d6c7cad5a4ea8fb5d9eb5 to your computer and use it in GitHub Desktop.
Save prerakmody/aa3996f2d40d6c7cad5a4ea8fb5d9eb5 to your computer and use it in GitHub Desktop.
Matplotlib Colors
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
cmap = matplotlib.cm.get_cmap('magma')
f,axarr = plt.subplots(1,3)
x = np.arange(0,1,0.01)
img = np.zeros((len(x),len(x),4))
for x_id, x_ in enumerate(x):img[x_id,:,:] = np.repeat(np.expand_dims(np.array(cmap(x_)), axis=0), len(x), axis=0)
axarr[0].imshow(img, cmap='magma')
x = np.arange(-1,2,0.01)
img = np.zeros((len(x),len(x),4))
for x_id, x_ in enumerate(x):img[x_id,:,:] = np.repeat(np.expand_dims(np.array(cmap(x_)), axis=0), len(x), axis=0)
axarr[1].imshow(img, cmap='magma')
x = np.arange(-1,255,0.1)
img = np.zeros((len(x),len(x),4))
for x_id, x_ in enumerate(x):img[x_id,:,:] = np.repeat(np.expand_dims(np.array(cmap(x_)), axis=0), len(x), axis=0)
axarr[2].imshow(img, cmap='magma')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment