teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

Update

2021/11/10 03:01

投稿

melian
melian

スコア21263

answer CHANGED
@@ -1,4 +1,4 @@
1
- `matplotlib.colors.from_levels_and_colors` を使って `level` から color map を作成します。ただし、`level` が `[-1, 2]` である事を前提としています。また、`legend` は `scatter.legend_elements()` を明示的に指定することで表示されるようになります。
1
+ `matplotlib.colors.from_levels_and_colors` を使って `level` から color map を作成します。`legend` は `scatter.legend_elements()` を明示的に指定することで表示されるようになります。
2
2
  ```python
3
3
  from sklearn.cluster import DBSCAN
4
4
  from sklearn.datasets import make_blobs
@@ -14,7 +14,7 @@
14
14
  min_samples = [2, 3, 5]
15
15
  epses = [1.0, 1.5, 2.0, 3.0]
16
16
 
17
- levels = np.arange(-1, 4) # [-1, 0, 1, 2, 3]
17
+ levels = np.arange(y.min()-1, y.max()+2)
18
18
  colors = ["red", "blue", "green", "yellow"]
19
19
  cmap, norm = matplotlib.colors.from_levels_and_colors(levels, colors)
20
20