Python 从Matplotlib中的轮廓线中删除线
我正在使用以下代码使用Python 从Matplotlib中的轮廓线中删除线,python,matplotlib,Python,Matplotlib,我正在使用以下代码使用matplotlib中的contourf等高线绘制一些数据。我已经将色条的透明度设置为0.6,但是在每个颜色间隔之间都有一些我无法消除的恼人的线条。在contourf中似乎没有设置linestyle的方法,有什么想法吗 #instantiating and titiling the figure fig, ax1 = plt.subplots(figsize=(7,5)) fig.suptitle('Testing Simple Neural Networks', y=0.
matplotlib
中的contourf
等高线绘制一些数据。我已经将色条的透明度设置为0.6,但是在每个颜色间隔之间都有一些我无法消除的恼人的线条。在contourf
中似乎没有设置linestyle
的方法,有什么想法吗
#instantiating and titiling the figure
fig, ax1 = plt.subplots(figsize=(7,5))
fig.suptitle('Testing Simple Neural Networks', y=0.96, fontsize=16, fontweight='bold');
#defining colour tables
cm = plt.cm.coolwarm
#plotting the contour plot
levels = np.linspace(0, 1, 25)
cont1 = ax1.contourf(p1_mesh, p2_mesh, y_mesh, levels=levels, cmap=cm, alpha=0.6, linewidths=10)
#plotting the entire dataset - training and test data.
scat1 = ax1.scatter(X['p1'],
X['p2'],
c=y,
cmap=cm,
edgecolors='k');
#setting axis and legend
ax1.set(ylabel='p2',
xlabel='p1',
xlim=(0,255),
ylim=(0,255));
ax1.legend(*scat1.legend_elements(), title='Target');
ax1.set_axisbelow(True)
ax1.grid(color='xkcd:light grey')
cbar = fig.colorbar(cont1)
您可以将选项
抗锯齿=True
添加到ax1.tourtf
,它应该会修复它。尝试从ax1.tourtf()
中删除线宽=10
。是的,我实际上把它作为一种检查,看看它是否对那些并不不幸的行产生了任何影响。正如我后来在中检查的,线宽
和线型
仅影响轮廓
而非轮廓
。