Created
August 27, 2013 15:45
-
-
Save cpelley/6355283 to your computer and use it in GitHub Desktop.
Matplotlib colormap plotting (specified/all)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
a = np.linspace(0, 1, 256).reshape(1,-1) | |
a = np.vstack((a,a)) | |
plot_spec = None | |
if plot_spec is None: | |
# Get a list of the colormaps in matplotlib. Ignore the ones that end with | |
# '_r' because these are simply reversed versions of ones that don't end | |
# with '_r' | |
maps = sorted(m for m in plt.cm.datad if not m.endswith("_r")) | |
nmaps = len(maps) + 1 | |
fig = plt.figure(figsize=(5,10)) | |
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99) | |
for i,m in enumerate(maps): | |
ax = plt.subplot(nmaps, 1, i+1) | |
plt.axis("off") | |
plt.imshow(a, aspect='auto', cmap=plt.get_cmap(m), origin='lower') | |
pos = list(ax.get_position().bounds) | |
fig.text(pos[0] - 0.01, pos[1], m, fontsize=10, horizontalalignment='right') | |
else: | |
fig = plt.figure(figsize=(5,5)) | |
plt.axis('off') | |
plt.imshow(a, aspect='auto', cmap=plt.get_cmap(plot_spec)) | |
fig.text(0.5, 0.95, plot_spec, fontsize=10, verticalalignment='center', | |
horizontalalignment='center') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment