The default cmap is sns.cm.rocket. To reverse it set cmap to sns.cm.rocket_r
Using your code:
cmap = sns.cm.rocket_r
ax = sns.heatmap(cm_prob,
annot=False,
fmt=".3f",
xticklabels=print_categories,
yticklabels=print_categories,
vmin=-0.05,
cmap = cmap)
Answer from Ben on Stack OverflowThe default cmap is sns.cm.rocket. To reverse it set cmap to sns.cm.rocket_r
Using your code:
cmap = sns.cm.rocket_r
ax = sns.heatmap(cm_prob,
annot=False,
fmt=".3f",
xticklabels=print_categories,
yticklabels=print_categories,
vmin=-0.05,
cmap = cmap)
To expand on Ben's answer, you can do this with most if not any color map.
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
X = np.random.random((4, 4))
sns.heatmap(X,cmap="Blues")
plt.show()
sns.heatmap(X,cmap="Blues_r")
plt.show()
sns.heatmap(X,cmap="YlGnBu")
plt.show()
sns.heatmap(X,cmap="YlGnBu_r")
plt.show()

python - How to reverse colorscales in seaborn heatmap - Stack Overflow
How do I reverse the direction of the color shading in seaborn barplot ?
python - How does cmap work in seaborn and how to change binning? - Stack Overflow
python 3.x - create custom cmap for seaborn heatmap - Stack Overflow
You can reverse all of the matplotlib colormaps by appending _r to the name, i.e., plt.cm.coolwarm vs plt.cm.coolwarm_r.
I believe seaborn uses a cubehelix colormap by default.
So you'd do:
from matplotlib import pyplot
import seaborn as sns
colormap = pyplot.cm.cubehelix_r
flights = sns.load_dataset('flights').pivot("month", "year", "passengers")
sns.heatmap(flights, cmap=colormap)
There is no need to build a separate reverse function for heatmap.
Just use cmap = 'magma_r'. The default setting is magma and thus we just append the '_r' for reverse.
Expected - Getting this output in Jupyter Notebook. This is what I want.
https://i.imgur.com/lUgNDIU.png
I'm getting this when I run the same python file from the Terminal. But I want the opposite direction of colors.
https://i.imgur.com/9pDQtKL.png
This is my code :
https://pastebin.com/KFCkG6Qw
