I am trying to plot a heatmap using seaborn library.
The plotting function looks like this:
def plot_confusion_matrix(data, labels, **kwargs):
"""Visualize confusion matrix as a heat map."""
col_map = kwargs.get('color_palette', sns.light_palette('navy', n_colors=5, as_cmap=False))
sns.heatmap(
vmin=0.0,
vmax=1.0,
data=data,
cmap=col_map,
xticklabels=labels,
yticklabels=labels,
linewidths=0.75,
)
The histogram of the data
, however, looks like this:
Now the issue I am struggling with is that seaborn heatmap(view bellow) splits evenly the color scale and hence most of the data has the same color (since the data is not evenly distributed).
I was not able to find out how to set some sort of intervals or boundaries for the color levels.
Suppose I have the following array of hex color values:
['#e5e5ff', '#acacdf', '#7272bf', '#39399f', '#000080']
Is there a way to set up a color such as
[(threshold_0, hex_0), (threshold_1, hex_1), ..., (threshold_n, hex_n)]
where threshold_i
is a value in range [0, 1)
Appreciate any help.
PS: current heatmap for illustration:
Knowingly not addressing the "custom" in your question - perhaps this helps in the meantime:
Beneath well known colormaps which change smoothly over the whole range, there are also a few which are suited better to show small differences in several bands of data, gist_ncar
for example.
See also https://matplotlib.org/examples/color/colormaps_reference.html
created with
sns.heatmap(vmin=0.0, vmax=1.0, data=data, cmap='gist_ncar', linewidths=0.75)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With