Issue
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?
#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)
Solution
You can add the option antialiased=True
to ax1.contourf
, it should fix it.
Answered By - bb1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.