How to manually define color bar scale in seaborn heatmap - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to manually define color bar scale in seaborn heatmap (/thread-16540.html) |
How to manually define color bar scale in seaborn heatmap - SriRajesh - Mar-04-2019 Hi, I want to define color bar, how to define manually. I use below example: import numpy as np; np.random.seed(0) import seaborn as sns; sns.set() uniform_data = np.random.rand(10, 12) ax = sns.heatmap(uniform_data)The automatic color bar ticks getting here are 0.2,0.4,0.6,0.8, but I want to display 0.0,0.2,0.4,0.6,0.8,1.0. How to make this. RE: How to manually define color bar scale in seaborn heatmap - scidam - Mar-06-2019 Try the following example: import matplotlib.pyplot as plt import seaborn as sns; sns.set() uniform_data = np.random.rand(10, 12) ax = sns.heatmap(uniform_data, cbar_kws={'ticks': [0.0, 0.2, 0.4, 0.5, 0.7, 0.8, 1.0]}, vmin=0, vmax=1) plt.show() RE: How to manually define color bar scale in seaborn heatmap - SriRajesh - Mar-06-2019 Thanks, it works. RE: How to manually define color bar scale in seaborn heatmap - RudraMohan - Sep-08-2019 Hi Rajesh, When we create seaborn heatmap then automatically color bar also generate. Depend on creator requirement, we can modify it. You want to display ticks, so use cbar_kws sns.heatmap() parameter and pass keys(ticks) and values mapping for change the style and format of seaborn heatmap color bar import numpy as np; np.random.seed(0) import seaborn as sns; sns.set() uniform_data = np.random.rand(10, 12) # color bar keyword arguments cbar_kws = {"shrink":1, 'extend':'min', 'extendfrac':.1, "drawedges":True, 'ticks': [0.0, 0.2, 0.4, 0.5, 0.7, 0.8, 1.0], # set ticks of color bar 'label':'Color Bar'} ax = sns.heatmap(uniform_data, cbar_kws=cbar_kws, vmin=0, vmax=1) |