Python数据可视化 - 使用Matplotlib库绘制点图、折线图、条状图与饼图

Notes(2019.04.06):

Data Visiable with matplotlib.pyplot - Using matplotlib.pyplot:
>>> import matplotlib.pyplot as plt


New Words:
plot = picture = figure
sub-A:the child of A


First:
#title中的loc只可以放在上方的left/center/right!

	0.Draw many sub-figures in one main-figure
		plt.figure(num=2)


	1.indicate a area of number
		numpy.arange(1,10,2)    #can own float in it!!!
		range(1,10,2)    #only integer!!!
		np.array([...])    #any type!!!
	attention:the two ways above support index and slice visit


	2.divide area of figure (row,column,position -> from row)
		matplotlib.pyplot.subplot(2,2,1)
		matplotlib.pyplot.subplot(221)
		matplotlib.pyplot.show()


	3.scatter figure
		matplotlib.pyplot.scatter(List1,List2,color,marker)
		matplotlib.pyplot.title("...")
		matplotlib.pyplot.show()


	4.plot figure
		plt.plot(List1,List2,color='red','o-/o/-/./--/-./:')
		plt.plot(x, y, 'ro-',label="xxx")  # red+solid-point+line
			plt.xlabel("...")
			plt.ylabel("...")
			matplotlib.pyplot.title("...")
				plt.xlim(a,b)    # limit the x-axis
				plt.ylim(c,d)	 # limit the y-axis
			plt.grid()    #show grid

		plt.legend(loc="upper left")    #generate legend by plot-labels
		matplotlib.pyplot.show()


	5.bar figure
		def draw_bar():
                x = np.array(["Frank", "kiroto", "pixel", "Lisa", "Bostor"])
                y = np.array([45, 12, 23, 78, 9])
                z = np.array([12, 45, 55, 19, 66])
                plt.subplot(211)
                plt.bar(np.arange(5), y, width=0.3, color='red', label="Life")
                plt.bar(np.arange(5)+0.3, z, width=0.3, color='green', label="Entertainment")
                plt.title("Person's ability", fontsize=12)
                plt.xlabel("Name", fontsize=12)
                plt.ylabel("Score", fontsize=12)
                plt.grid()
                plt.legend(loc='upper left')
                plt.subplot(212)
                plt.bar(x, height=y, color='red', width=0.3, label='Life')
                plt.title("Person's ability", fontsize=12)
                plt.xlabel("Name", fontsize=12)
                plt.ylabel("Score", fontsize=12)
                plt.xticks([0, 1, 2, 3, 4], ["A", "B", "C", "D", "E"])
                plt.grid()
           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值