I am using the following code to contour plot some data using contourf
in matplotlib
. I have set the transparency of the colourbar to 0.6, but there are annoying lines between each colour interval that I cant get rid of. There doesnt seem to be a way to set linestyle
in contourf
, any ideas?
JavaScript
x
28
28
1
#instantiating and titiling the figure
2
fig, ax1 = plt.subplots(figsize=(7,5))
3
fig.suptitle('Testing Simple Neural Networks', y=0.96, fontsize=16, fontweight='bold');
4
5
#defining colour tables
6
cm = plt.cm.coolwarm
7
8
#plotting the contour plot
9
levels = np.linspace(0, 1, 25)
10
cont1 = ax1.contourf(p1_mesh, p2_mesh, y_mesh, levels=levels, cmap=cm, alpha=0.6, linewidths=10)
11
12
#plotting the entire dataset - training and test data.
13
scat1 = ax1.scatter(X['p1'],
14
X['p2'],
15
c=y,
16
cmap=cm,
17
edgecolors='k');
18
19
#setting axis and legend
20
ax1.set(ylabel='p2',
21
xlabel='p1',
22
xlim=(0,255),
23
ylim=(0,255));
24
ax1.legend(*scat1.legend_elements(), title='Target');
25
ax1.set_axisbelow(True)
26
ax1.grid(color='xkcd:light grey')
27
cbar = fig.colorbar(cont1)
28
Advertisement
Answer
You can add the option antialiased=True
to ax1.contourf
, it should fix it.