Heat Maps Seaborn Annot Error

2019-06-09 04:29发布

问题:

As extension to my previous question

With same data set I am not able to get the annotation done.

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()

df = pd.read_csv('heat_map_data.csv')

df3 = df.copy()
for c in ['Place','Name']:
    df3[c] = df3[c].astype('category')

sns.heatmap(df3.pivot_table(index='Place', columns='Name', values='00:00:00', annot=True) )

plt.show() 

Error:

Traceback (most recent call last):
  File "heatmap_sns.py", line 13, in <module>
    sns.heatmap(df3.pivot_table(index='Place', columns='Name', values='00:00:00', annot=True) )
TypeError: pivot_table() got an unexpected keyword argument 'annot'

Please suggest what could be the fix ?

回答1:

annot=True is an argument of heatmap, not pivot_table:

sns.heatmap(df3.pivot_table(index='Place', columns='Name', values='00:00:00'), 
            annot=True)