Auto adjust font size in seaborn heatmap

前端 未结 4 2088
一向
一向 2020-12-07 00:40

when using seaborn heatmap, is there a way to auto-adjust the font size for it to fit exactly inside the squares? for example in:

sns.heatmap(corrmat, vmin=         


        
4条回答
  •  天命终不由人
    2020-12-07 01:00

    To adjust the font size of seaborn heatmap, there are different methods

    import seaborn as sns # for data visualization
    flight = sns.load_dataset('flights') # load flights datset from GitHub seaborn repository
    
    # reshape flights dataeset in proper format to create seaborn heatmap
    flights_df = flight.pivot('month', 'year', 'passengers') 
    
    sns.heatmap(flights_df) # create seaborn heatmap
    
    sns.set(font_scale=2) # font size 2
    

    Output >>>

    the sns.set(font_scale=2) # font size 2 set size for all seaborn graph labels that's reason follow another method if you like

    import seaborn as sns # for data visualization
    import matplotlib.pyplot as plt # for data visualization
    
    flight = sns.load_dataset('flights') # load flights datset from GitHub seaborn repository
    
    # reshape flights dataeset in proper format to create seaborn heatmap
    flights_df = flight.pivot('month', 'year', 'passengers') 
    
    sns.heatmap(flights_df) # create seaborn heatmap
    
    
    plt.title('Heatmap of Flighr Dataset', fontsize = 20) # title with fontsize 20
    plt.xlabel('Years', fontsize = 15) # x-axis label with fontsize 15
    plt.ylabel('Monthes', fontsize = 15) # y-axis label with fontsize 15
    
    plt.show()
    

    Output >>>

提交回复
热议问题