pythonbook/实例学习d3blocks/test.py

30 lines
858 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 导入d3blocks
from d3blocks import D3Blocks
import numpy as np
# 初始化
d3 = D3Blocks()
# 数据准备
df = d3.import_example('mnist')
size = np.random.randint(0, 8, df.shape[0])
opacity = np.random.randint(0, 8, df.shape[0]) / 10
tooltip = df['y'].values.astype(str)
# 绘图
d3.scatter(
df['PC1'].values, # PCA图主成分PC1 x轴数据
df['PC2'].values, # PCA图主成分PC2 y轴数据
x1=df['tsne_1'].values, # tSNE图x轴数据
y1=df['tsne_2'].values, # tSNE图y轴数据
color=df['y'].values.astype(str),
tooltip=tooltip, # 设置点的值
size=size,
opacity=opacity, # 设置点透明度
stroke='#000000',
cmap='tab20', # 设置Colormap
scale=True,
label_radio=['PCA', 'tSNE'],
figsize=[1024, 768],
filepath='scatter_demo.html', #设置结果名称结果为网页html格式
)