1.畫點(diǎn)狀圖
import pylab as pl
import matplotlib
x=[10,20,11,12,15,25]
y=[3,6,9,8,7,4]
co=[1,2,3,4,5,6]
fig1=pl.figure()
for i in range(0,len(x)):
pl.plot(x[i],y[i],'o',color=cm(co[i]*1.0/6)) #畫點(diǎn)狀圖
plt.scatter(random(10), random(10), marker='x', color=colors[0])
pl.text(x[i],y[i],str(y[i])+'*',color='red') #在某個(gè)位置寫字
pl.xlim(0,45)
pl.title('cluster graph ')
pl.show()
#=========================
pl.bar(x,y) #畫柱狀圖
2.柱狀圖
import matplotlib.pyplot as plt
import numpy as np
dict = {'A': 40, 'B': 70, 'C': 30, 'D': 85}
for i, key in enumerate(dict):#Circulate both index and value(Here is key)
plt.bar(i, dict[key], color='r', width=0.2)
plt.xticks(np.arange(len(dict))+0.1, dict.keys())#Translation
plt.yticks(dict.values())
plt.grid(True)
plt.show()
3.折線圖
x = []
yQ = []
yARI = []
delta = 0
while delta <= 1.0:
x.append(delta)
ARI = Evaluation.calculateARI(true_labels, predict)
Q = Evaluation.calculateQ(G, communities)
yARI.append(ARI)
yQ.append(Q)
delta += 0.1
# end of while
pl.plot(x, yARI)
pl.plot(x, yNMI)
pl.plot(x, yQ)
pl.plot(x, yPurity)
pl.legend(('ARI', 'Q'), loc='upper right')
pl.ylim(0, 1.1)
pl.show()
4.畫多個(gè)子圖
fig1=plt.figure()
fig1.add_subplot(4,1,1)
plt.plot(x1,y1)
fig1.add_subplot(4,1,2)
plt.plot(x2,y2)
fig1.add_subplot(4,1,3)
plt.plot(x3,y3)
fig1.add_subplot(4,1,4)
plt.plot(x4,y4)
5.帶有顏色深淺的散點(diǎn)圖:
x=[1, 1, 2, 3, 5]
y=[1.2, 1.1, 5, 4, 2]
z=[ 1, 3, 8, 5, 2 ]
plt.scatter(x, y, c=z,s=50)
plt.colorbar()
plt.show()
效果:
6.顏色
顏色之間的對應(yīng)關(guān)系為
b—blue c—cyan g—green k—-black
m—magenta r—red w—white y—-yellow
有三種表示顏色的方式:
a:用全名 b:16進(jìn)制如:#FF00FF c:RGB或RGBA元組(1,0,1,1) d:灰度強(qiáng)度如:‘0.7’
7.點(diǎn)的形狀
標(biāo)記風(fēng)格有多種:
. Point marker
, Pixel marker
o Circle marker
v Triangle down marker
^ Triangle up marker
< Triangle left marker
> Triangle right marker
1 Tripod down marker
2 Tripod up marker
3 Tripod left marker
4 Tripod right marker
s Square marker
p Pentagon marker
* Star marker
h Hexagon marker
H Rotated hexagon D Diamond marker
d Thin diamond marker
| Vertical line (vlinesymbol) marker
_ Horizontal line (hline symbol) marker
+ Plus marker
x Cross (x) marker
8.線的形狀
符號和線型之間的對應(yīng)關(guān)系
- 實(shí)線
-- 短線
-. 短點(diǎn)相間線
: 虛點(diǎn)線
plt.plot(y, 'cx--', y+1, 'mo:', y+2, 'kp-.');
9. 畫網(wǎng)絡(luò)圖
對網(wǎng)絡(luò)數(shù)據(jù)畫圖。需要安裝networkx網(wǎng)絡(luò)。
import networkx as nx
pos=nx.spectral_layout(G)
clusterResult=[ ]是節(jié)點(diǎn)的社區(qū)劃分結(jié)果
nx.draw(G,with_labels=True,node_color=clusterResult,node_size=300)
plt.show()