scatter绘制散点图示例

scatter绘制散点图示例

1、example 1

from sklearn import datasets
digits = datasets.load_digits()
import matplotlib.pyplot as plt

colors = ['black', 'blue', 'purple', 'yellow', 'white', 'red', 'lime', 'cyan', 'orange', 'gray']
for i in range(len(colors)):
    x = reduced_data_rpca[:, 0][digits.target == i]
    y = reduced_data_rpca[:, 1][digits.target == i]
    plt.scatter(x, y, c=colors[i])
plt.legend(digits.target_names, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.xlabel('First Principal Component')
plt.ylabel('Second Principal Component')
plt.title("PCA Scatter Plot")
plt.show()

图片:

scatter绘制散点图示例_第1张图片

2、example 2

from sklearn import datasets
import matplotlib.pyplot as plt
import pylab as Plot
import numpy as np
import scipy.io as sio
colors = ['black', 'blue', 'purple', 'yellow', 'white', 'red', 'lime', 'cyan', 'orange', 'gray']
mat_ = sio.loadmat('softmax.mat')
X = mat_['dataset_feats']
data = X[0:200,:]
data = np.array(data)
labels = mat_['dataset_labels']
labels = labels[0,0:200]
labels = np.array(labels)
l = np.unique(labels)
Y = sio.loadmat('Y.mat')
Y = Y['Y']
Y = np.array(Y)
colors = ['black', 'blue', 'purple', 'yellow', 'white', 'red', 'lime', 'cyan', 'orange', 'gray']
idx = []
for i in range(len(colors)):
    idx = np.where(labels==i)
    plt.scatter(Y[idx,0], Y[idx,1],color = colors[i], label= l[i] , s = 20)
plt.legend(loc='upper right')
plt.show()

图片:
scatter绘制散点图示例_第2张图片

3、example 3

import matplotlib.pyplot as plt
import numpy as np

n = 100

for color in ['red','blue','green']:
    x,y=np.random.rand(2,n)
    scale=100*np.random.rand(n)
    plt.scatter(x,y,c=color,s=scale,label=color,alpha=0.6,edgecolors='white')

plt.title('Scatter')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True)
plt.show()

图片:
scatter绘制散点图示例_第3张图片

你可能感兴趣的:(python)