以下代碼繪製兩個紅色矩形。 紅色長方形應該彼此相鄰,兩者之間沒有空格。在python情節中,這是可以的。在導出的pdf中,矩形之間有一個薄而明顯的空白區域。有沒有解決這個問題的方法?matplotlib中的矩形修補程序之間不需要的空間
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.patches as patches
fig1 = plt.figure();
ax = fig1.add_subplot(111, aspect='equal');
ax.set_xticks([]);
ax.set_yticks([]);
#add first patch
dx=1.0;
loc=(0.0,0.0);
ax.add_patch(patches.Rectangle((loc[0]-dx/2.0,loc[1]-dx/2.0),dx,dx,facecolor='red',edgecolor='none',linewidth=0));
#add second patch
dx=1.0;
loc=(1.0,0.0);
ax.add_patch(patches.Rectangle((loc[0]-dx/2.0,loc[1]-dx/2.0),dx,dx,facecolor='red',edgecolor='none',linewidth=0));
ax.set_xlim([-1,3]);
ax.set_ylim([-1,2]);
fig1.show();
plt.savefig('spaceTest.pdf');
一個解決辦法可能是使用了'edgecolor'(即其設置爲相同的顏色)? – DilithiumMatrix