Make the size of a heatmap bigger with seaborn

后端 未结 3 735
粉色の甜心
粉色の甜心 2021-01-31 07:22

I create a heatmap with seaborn

df1.index = pd.to_datetime(df1.index)
df1 = df1.set_index(\'TIMESTAMP\')
df1 = df1.resample(\'30min\').mean()
ax = sns.heatmap(         


        
相关标签:
3条回答
  • 2021-01-31 07:56

    add plt.figure(figsize=(16,5)) before the sns.heatmap and play around with the figsize numbers till you get the desired size

    ...
    
    plt.figure(figsize = (16,5))
    
    ax = sns.heatmap(df1.iloc[:, 1:6:], annot=True, linewidths=.5)
    
    0 讨论(0)
  • 2021-01-31 08:03

    I do not know how to solve this using code, but I do manually adjust the control panel at the right bottom in the plot figure, and adjust the figure size like:

    f, ax = plt.subplots(figsize=(16, 12))
    

    at the meantime until you get a matched size colobar. This worked for me.

    0 讨论(0)
  • 2021-01-31 08:08

    You could alter the figsize by passing a tuple showing the width, height parameters you would like to keep.

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(figsize=(10,10))         # Sample figsize in inches
    sns.heatmap(df1.iloc[:, 1:6:], annot=True, linewidths=.5, ax=ax)
    

    EDIT

    I remember answering a similar question of yours where you had to set the index as TIMESTAMP. So, you could then do something like below:

    df = df.set_index('TIMESTAMP')
    df.resample('30min').mean()
    fig, ax = plt.subplots()
    ax = sns.heatmap(df.iloc[:, 1:6:], annot=True, linewidths=.5)
    ax.set_yticklabels([i.strftime("%Y-%m-%d %H:%M:%S") for i in df.index], rotation=0)
    

    For the head of the dataframe you posted, the plot would look like:

    0 讨论(0)
提交回复
热议问题