Python data visualization-scatter chart and python data visualization
PS: I flipped through the draft box and found that I saved an article in last February... Although naive, send it...
This article records data visualization in python-scatter Plot scatter,
Make x as data (50 points, 30 dimensions each), we only visualize the first two dimensions. Labels is its category (assume there are three categories ).
Here, "x" uses random to analyze specific data.
Label is set to []-> 1, []-> 2, [36: 50]-> 3, (array connection method in python: Convert to list first, +, and then returns to array)
Use matplotlib's scatter to draw a scatter chart. legend and matlab are slightly different. For details, see the code.
x = rand(50,30)
from numpy import *
import matplotlib
import matplotlib.pyplot as plt
#basic
f1 = plt.figure(1)
plt.subplot(211)
plt.scatter(x[:,1],x[:,0])
# with label
plt.subplot(212)
label = list(ones(20))+list(2*ones(15))+list(3*ones(15))
label = array(label)
plt.scatter(x[:,1],x[:,0],15.0*label,15.0*label)
# with legend
f2 = plt.figure(2)
idx_1 = find(label==1)
p1 = plt.scatter(x[idx_1,1], x[idx_1,0], marker = 'x', color = 'm', label='1', s = 30)
idx_2 = find(label==2)
p2 = plt.scatter(x[idx_2,1], x[idx_2,0], marker = '+', color = 'c', label='2', s = 50)
idx_3 = find(label==3)
p3 = plt.scatter(x[idx_3,1], x[idx_3,0], marker = 'o', color = 'r', label='3', s = 15)
plt.legend(loc = 'upper right')
Result:
Figure (1 ):
Figure (2 ):