0

I am getting mad trying to make a heatmap with a logarithmic color scale. I have a dataset where the values have a very high variance, and there are a few outliers which have a value way higher than the mean. Thus, if I try to make a heatmap out of this dataset using a linear color scale, most of the points will be at the very beginning of the scale, resulting in an almost completely black matrix (assuming that the color scale goes from black to red). Here it is the result, made with seaborn:

import seaborn as sns
import pandas as pd
plt.figure(figsize = (16,10))
ax = sns.heatmap(table.iloc[:,0:20],xticklabels=False) #table is the dataframe

heatmap

The fact is that I am struggling a lot to change the colorscale, and I would appreciate any suggestion in this sense. I am also open to completely change the library, I don't care the tool I use, I just care about the result as long as I stick to Python. I have tried seaborn, plotly, altair but each of them seems to have issues with this particular task. Is there something I am missing?

EDIT: Since the question has been marked as duplicate, I was aware of the other question but I couldn't solve my issue by following any of the advices in the replies.

sato
  • 768
  • 1
  • 9
  • 30
  • MatplotLib?? Many times, you can find examples in the Matplotlib Gallery/examples that can be adapted to your purposes. I often just browse through it to see if I can find features I want in an example then look to see how they did it. - [pylab_examples example code: pcolor_log.py](https://matplotlib.org/examples/pylab_examples/pcolor_log.html). [Colormap Normalization](https://matplotlib.org/users/colormapnorms.html#logarithmic) – wwii May 07 '18 at 15:59
  • Can you add some sample data? – Maximilian Peters May 07 '18 at 16:15
  • 1
    I would suggest to transform the dataset, instead of losing the reason on the transformation through matplotlib. Try this command: df.transform(lambda x: np.log(x)) – el_Rinaldo May 07 '18 at 16:23

0 Answers0