I'm plotting multiple heatmaps. The code is as follows:
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
FONTSIZE=20
fig, axes = plt.subplots(nrows=1, ncols=4,figsize=(12,3))
k=0
for 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 side
cax = 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')
The figure is as follows:
How can I remove the white lines in each subplot? It is astonishing. I find that if I remove the import seaborn as sns
, then the white lines disappear. But in that case, the figure will looks ugly.
How can I remove the white lines and in the meanwhile keep the looking of the figure similar to the current looking?
Thank you all for helping me!
You can turn the grid off via
import matplotlib.pyplot as plt
plt.rcParams["axes.grid"] = False
This should be done before importing seaborn.
In seaborn version < 0.8 the import of seaborn automatically sets the style to the darkgrid
, which defines axes.grid : True
. This would need to be reverted as shown above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With