Python Forum
y-axis on seaborn heatmap not aligned properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
y-axis on seaborn heatmap not aligned properly
#1
Hi all,

I am having an issue with a heatmap on seaborn when using pycharm (not sure if this is the right forum so apologies if this is the case)

I am not having this issue when i run this code in google colab, so i am unsure as to what the issue is. I have created a function to build a confusion matrix as follows:

def kerasConfMat (classLabelPDindex,classLabelPDCols,reorderCols,reorderRows,actual, pred,hmcolor, xlab, ylab,fontsize, titlelab,titleFontSize, xAxislab,yAxislab, axisLabFontSize, colorbarlegend, annotatePlot) :

    cm = confusion_matrix(actual.argmax(axis=1), pred.argmax(axis=1))
    cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]

    df_cm = pd.DataFrame(cm, index=classLabelPDindex, columns=classLabelPDCols)


    df_cm = df_cm[reorderCols]
    df_cm = df_cm.reindex(index=reorderRows)
    print(df_cm)

    ax = plt.axes()

    plot=seaborn.heatmap(df_cm, cmap=hmcolor, xticklabels=xlab, yticklabels=ylab, ax=ax, cbar=colorbarlegend, annot=annotatePlot)
    ax.set_title(titlelab, fontsize=titleFontSize)
    plt.xlabel(xAxislab, fontsize=axisLabFontSize)
    plt.ylabel(yAxislab, fontsize=axisLabFontSize)

    plot.yaxis.set_ticklabels(plot.yaxis.get_ticklabels(), rotation=0, ha='center', fontsize=fontsize)
    plot.xaxis.set_ticklabels(plot.xaxis.get_ticklabels(), rotation=45, ha='center', fontsize=fontsize)


    return plot
# Dependencies
import seaborn
from sklearn.metrics import confusion_matrix
The issue is the y-axis and some of the body of the plot. The y-axis is overlapping or in the incorrect position on the y-axis and the blocks of colour in the main plot look zoomed in slightly. i have no idea why it is plotting like this as this has worked previously in pycharm without issues with this code. also, if i run the normal seaborn code without it implemented in the function, it is the same...

please see image attached for example that was run today.    

any help would be much appreciated!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,644 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  How to plot seaborn heatmap on top of a background circle SriRajesh 0 1,398 Jul-09-2022, 04:00 AM
Last Post: SriRajesh
  Installing and Using Seaborn Led_Zeppelin 4 2,539 Jun-07-2022, 09:44 PM
Last Post: snippsat
  How to increase the size of a png picture for the heatmap of the correlation? lulu43366 9 3,492 Oct-06-2021, 04:15 PM
Last Post: deanhystad
  How to remove a column or two columns in a correlation heatmap? lulu43366 3 5,189 Sep-30-2021, 03:47 PM
Last Post: lulu43366
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,299 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,459 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123
  titanic from Seaborn matador 3 4,631 Aug-20-2020, 12:13 PM
Last Post: buran
  seaborn scatterplot npiatti 1 1,877 Mar-03-2020, 01:54 PM
Last Post: scidam
  How to manually define color bar scale in seaborn heatmap SriRajesh 3 18,262 Sep-08-2019, 11:12 AM
Last Post: RudraMohan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020