Auto adjust font size in seaborn heatmap

前端 未结 4 2089
一向
一向 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:07

    Although it distorts the heatmap, this example illustrates how to scale the font using .set(...) context

    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set(font_scale=3)
    
    # Load the example flights dataset and conver to long-form
    flights_long = sns.load_dataset("flights")
    flights = flights_long.pivot("month", "year", "passengers")
    
    # Draw a heatmap with the numeric values in each cell
    f, ax = plt.subplots(figsize=(9, 6))
    sns.heatmap(flights, annot=True, fmt="d", linewidths=.5, ax=ax)
    f.savefig("output.png")
    

提交回复
热议问题