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

前端 未结 11 1156
猫巷女王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:10

    matplotlib 3.1.2 is out - It is available in the Anaconda cloud via conda-forge but I was not able to install it via conda install. The manual alternative worked: Download matplotlib 3.1.2 from github and install via pip

     % curl https://codeload.github.com/matplotlib/matplotlib/tar.gz/v3.1.2 --output matplotlib-3.1.2.tar.gz
     % pip install matplotlib-3.1.2.tar.gz
    
    0 讨论(0)
  • 2020-11-21 14:13

    Worked for me:

    b, t = plt.ylim()
    b += 0.5
    t -= 0.5
    custom_ylim = (b, t)
    plt.setp(axes, ylim=custom_ylim)
    
    0 讨论(0)
  • 2020-11-21 14:19

    Unfortunately matplotlib 3.1.1 broke seaborn heatmaps; and in general inverted axes with fixed ticks.
    This is fixed in the current development version; you may hence

    • revert to matplotlib 3.1.0
    • use matplotlib 3.1.2 or higher
    • set the heatmap limits manually (ax.set_ylim(bottom, top) # set the ylim to bottom, top)
    0 讨论(0)
  • 2020-11-21 14:19

    I solved this problem with the following code:

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

    rustyDev is right about conda-forge, but I did not need to do a manual pip install from a github download. For me, on Windows, it worked directly. And the plots are all nice again.

    https://anaconda.org/conda-forge/matplotlib

    conda install -c conda-forge matplotlib
    

    optional points, not needed for the answer:

    Afterwards, I tried other steps, but they are not needed: In conda prompt: conda search matplotlib --info showed no new version info, the most recent info was for 3.1.1. Thus I tried pip using pip install matplotlib==3.1.2 But pip says "Requirement already satisfied"

    Then getting the version according to medium.com/@rakshithvasudev/… python - import matplotlib - matplotlib.__version__ shows that 3.1.2 was successfully installed

    Btw, I had this error directly after updating Spyder to v4.0.0. The error was in a plot of a confusion matrix. This was mentioned already some months ago. stackoverflow.com/questions/57225685/… which is already linked to this seaborn question.

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