Bivariate colormap solutions
Bivariate colormap solutions.
This package makes it easy to create custom two-dimensional colormaps, apply them to your series, and add bivariate color legends to your plots.
pip install xycmap
Make a custom interpolated colormap by specifying four corner colors (see recognized formats here), and dimensions
import xycmap corner_colors = ("lightgrey", "green", "blue", "red") n = (5, 5) # x, y cmap = xycmap.custom_xycmap(corner_colors=corner_colors, n=n)
Or make a colormap by mixing two matplotlib colormaps, and specifying dimensions
import matplotlib.pyplot as plt xcmap = plt.cm.rainbow ycmap = plt.cm.Greys n = (5, 5) # x, y cmap = xycmap.mean_xycmap(xcmap=xcmap, ycmap=ycmap, n=n)
With that in place, apply the colormap to two series that are numeric or categorical:
colors = xycmap.bivariate_color(sx=sx, sy=sy, cmap=cmap)
Note that you can apply limits to the axes, as well as pass custom bins for the axes (if numerical). See the docstring for details.
Then simply pass
colors to your plot. To add a legend, create a new ax and run
bivariate_legend() into the ax with the same parameters as
cax = fig.add_axes([1, 0.25, 0.5, 0.5]) cax = xycmap.bivariate_legend(ax=cax, sx=sx, sy=sy, cmap=cmap)
Distributed under the MIT license. See
LICENSE for more information.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.