我正在绘制多个热图。代码如下:import seaborn as snsimport numpy as npimport matplotlib.pyplot as pltFONTSIZE=20fig, axes = plt.subplots(nrows=1, ncols=4,figsize=(12,3))k=0for ax in axes.flat: mat = np.zeros((10,10)) + 0.5 im = ax.imshow(mat,interpolation='nearest', vmin=0.0, vmax=1.0,cmap='Reds') ax.set_xlim([-0.5, 9.0 + 0.5]) ax.set_ylim([-0.5, 9.0 + 0.5]) ax.set_xticks([0,5]) ax.set_yticks([0,5]) ax.set_xlabel('X',fontsize=FONTSIZE) if k == 0: ax.set_ylabel('Y',fontsize=FONTSIZE) ax.set_title('Title') k += 1# Make an axis for the colorbar on the right sidecax = fig.add_axes([0.99, 0.235, 0.03, 0.682])cbar = fig.colorbar(im, cax=cax,ticks=[0.0,0.1,0.2,0.3,0.4])cbar.ax.set_yticklabels(['0.0','0.1','0.2','0.3','0.4'])figtype = 'jpg'fig.tight_layout()fig.savefig('aaa.' + copy(figtype),format = figtype,bbox_inches='tight')图如下: 如何删除每个子图中的白线?这是惊人的。我发现如果我删除 import seaborn as sns ,那么白线就会消失。但在这种情况下,这个数字会看起来很丑。如何去除白线,同时保持图形的外观与当前外观相似?谢谢大家帮助我! 最佳答案 您可以通过以下方式关闭网格import matplotlib.pyplot as pltplt.rcParams["axes.grid"] = False这应该在导入 seaborn 之前完成。在 seaborn 版本 darkgrid ,它定义了 axes.grid : True 。这将需要恢复如上所示。关于python - Matplotlib:如何去除热图中的白线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45633160/
10-16 01:40