-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path03_07_iris_scatter_plot.py
42 lines (40 loc) · 1.2 KB
/
03_07_iris_scatter_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from sklearn.datasets import load_iris
from bokeh.io import show
from bokeh.plotting import figure
from bokeh.transform import factor_cmap
from bokeh.models import ColumnDataSource, NumeralTickFormatter
# Cargar datos de Iris
iris = load_iris()
# Separar características y etiquetas
X = iris.data
y = iris.target
# Crear ColumnDataSource
datos = {'sepal_length': X[:, 0], 'sepal_width': X[:, 1], 'petal_length': X[:, 2],
'petal_width': X[:, 3], 'clase': iris.target_names[y]}
source = ColumnDataSource(data=datos)
# Mapeo de colores por clase
colores = ["red", "green", "blue"] # Example color list
print(iris.target_names)
mapper = factor_cmap('clase', palette=colores, factors=iris.target_names)
# Crear figura de Bokeh
p = figure(
title="Diagrama de dispersión - Iris",
x_axis_label="Longitud del sépalo",
y_axis_label="Ancho del sépalo",
tools="pan,box_zoom,wheel_zoom,reset",
)
# Diagrama de dispersión
p.scatter(
x='sepal_length',
y='sepal_width',
size=10,
source=source,
fill_color=mapper,
fill_alpha=0.6,
line_color='gray',
)
# Personalizar ejes
p.xaxis.major_label_orientation = 1
p.yaxis.formatter = NumeralTickFormatter(format="0.0")
# Mostrar diagrama
show(p)