![]() |
y-axis on seaborn heatmap not aligned properly - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: y-axis on seaborn heatmap not aligned properly (/thread-21468.html) |
y-axis on seaborn heatmap not aligned properly - amjass12 - Oct-01-2019 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_matrixThe 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.[attachment=718] any help would be much appreciated! |