matplotlib/seaborn: first and last row cut in half of heatmap plot

前端 未结 11 1173
猫巷女王i
猫巷女王i 2020-11-21 13:35

When plotting heatmaps with seaborn (and correlation matrices with matplotlib) the first and the last row is cut in halve. This happens also when I run this minimal code exa

相关标签:
11条回答
  • 2020-11-21 14:01

    Fixed using the above and setting the heatmap limits manually.

    First

    ax = sns.heatmap(...
    

    checked the current axes with

    ax.get_ylim()
    (5.5, 0.5)
    

    Fixed with

    ax.set_ylim(6.0, 0)
    
    0 讨论(0)
  • 2020-11-21 14:01

    Downgrade your matplotlib

    !pip install matplotlib==3.1.0
    

    and add this line to your plot code :

    ax[i].set_ylim(sorted(ax[i].get_xlim(), reverse=True))
     
    
    0 讨论(0)
  • 2020-11-21 14:01

    conda install matplotlib=3.1.0

    This worked for me and downgraded matplotlib from 3.1.1 to 3.1.0 and the heatmaps started to behave correctly

    0 讨论(0)
  • 2020-11-21 14:02

    Its a bug in the matplotlib regression between 3.1.0 and 3.1.1 You can correct this by:

    import seaborn as sns
    df_corr = someDataFrame.corr()
    ax = sns.heatmap(df_corr, annot=True) #notation: "annot" not "annote"
    bottom, top = ax.get_ylim()
    ax.set_ylim(bottom + 0.5, top - 0.5)
    
    0 讨论(0)
  • 2020-11-21 14:06

    I solved it by adding this line in my code, with matplotlib==3.1.1:

    ax.set_ylim(sorted(ax.get_xlim(), reverse=True))

    NB. The only reason this works is because the x-axis isn't changed, so use at your own risk with future mpl versions

    0 讨论(0)
  • 2020-11-21 14:07

    It happens with matplotlib version 3.1.1 as suggested by importanceofbeingernest

    Following solved my problem

    pip install matplotlib==3.1.0

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