From 1a4cc0bb8564f3a292dca007ff8169d5a3c37281 Mon Sep 17 00:00:00 2001 From: i-aki-y Date: Sat, 14 Jan 2023 23:38:52 +0900 Subject: [PATCH] Fix color maps of contour and scatter plots. (#25329) Co-authored-by: Guillaume Lemaitre --- .../plot_kernel_approximation.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/miscellaneous/plot_kernel_approximation.py b/examples/miscellaneous/plot_kernel_approximation.py index 7dfc1e31220..afa07106950 100644 --- a/examples/miscellaneous/plot_kernel_approximation.py +++ b/examples/miscellaneous/plot_kernel_approximation.py @@ -223,12 +223,29 @@ for i, clf in enumerate((kernel_svm, nystroem_approx_svm, fourier_approx_svm)): # Put the result into a color plot Z = Z.reshape(grid.shape[:-1]) - plt.contourf(multiples, multiples, Z, cmap=plt.cm.Paired) + levels = np.arange(10) + lv_eps = 0.01 # Adjust a mapping from calculated contour levels to color. + plt.contourf( + multiples, + multiples, + Z, + levels=levels - lv_eps, + cmap=plt.cm.tab10, + vmin=0, + vmax=10, + alpha=0.7, + ) plt.axis("off") # Plot also the training points plt.scatter( - X[:, 0], X[:, 1], c=targets_train, cmap=plt.cm.Paired, edgecolors=(0, 0, 0) + X[:, 0], + X[:, 1], + c=targets_train, + cmap=plt.cm.tab10, + edgecolors=(0, 0, 0), + vmin=0, + vmax=10, ) plt.title(titles[i])