Created
May 25, 2018 19:58
-
-
Save AdrianLsk/0959e3004f0dc10dadf7201ce8e4cc69 to your computer and use it in GitHub Desktop.
Matplotlib utils
This file contains 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
"""Inspired by: | |
https://gist.github.com/jakevdp/91077b0cae40f8f8244a | |
http://joseph-long.com/writing/colorbars/ | |
""" | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |
def discrete_cmap(N, base_cmap=None): | |
"""Create an N-bin discrete colormap from the specified input map""" | |
base = plt.cm.get_cmap(base_cmap) | |
color_list = base(np.linspace(0, 1, N)) | |
cmap_name = base.name + str(N) | |
return base.from_list(cmap_name, color_list, N) | |
def colorbar(mappable, ticks): | |
ax = mappable.axes | |
fig = ax.figure | |
divider = make_axes_locatable(ax) | |
cax = divider.append_axes("right", size="5%", pad=0.05) | |
return fig.colorbar(mappable, cax=cax, ticks=ticks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment