一、matplotlib.pyplot绘图相关的对象
1、容器类:图(figure)、坐标系(axes)、坐标轴(axis)、刻度(tick)
2、基础类:线(line)、点(marker)、文本(text)、图例(legend)、网络(grid)、标题(title)
二、绘图的类型:
1、线形图:plot()
2、直方图:hist()
3、条形图:bar()
4、饼图:pie()
5、散点图:scatter()
6、3d图:from mpl_toolkita.mplt3d import Axes3D
7、动态交互图:pyecharts
#检查配置的环境
#导入第三方库
#1、线形图:plot()
#plt.plot([0,1,2,3,4],[4,8,6,9,10])
#plt.plot([4,6,7,8,10],[6,10,8,11,12])
#绘制平行四边形
plt.rcParams['font.family'] = 'Kaiti'#设置中文字体
plt.plot([1,5,6,2,1],[1,1,2,2,1]) #x坐标在前,y坐标在后,都用数组描述库,如果x坐标缺少,默认为0,1,2
plt.axis([0,8,0,4])#两位表示x轴,后两位表示y轴
plt.xlabel('课程')
plt.ylabel('成绩')
plt.title('立达学院数字科学学院各课程成绩')
plt.savefig('../R&Q_pic/test_0.png',dpi =600)
plt.show()#显示图片
#同一绘图区域绘制多图
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)#创建一个0-9的整数序列,作为x轴坐标
plt.plot(x,x*1.5,'ro-',label='a')
plt.plot(x,x*2.5,'gx-',label='b')
plt.plot(x,x*3.5,'y*',label='c')
plt.plot(x,x*4.5,'bs-',label='d')
plt.plot(x,x**2,'mH-',label='e')
plt.savefig('../R&Q_pic/test2',dpi=600)
plt.legend()
plt.show()
import matplotlib.pyplot as plt
import numpy as np
def f(t):
return np.exp(-t)*np.cos(2*np.pi*t)
a=np.arange(0.5,0.02)
plt.subplot(322)
plt.plot(a,f(a))
import matplotlib.pyplot as plt
plt.rcParams['font.family']="STSong"
years = ["2014","2015","2016","2017","2018","2019"]
baokao_nums =[172,164,177,201,238,290]
luqu_nums = [54,87,57,73,76,79]
x = range(len(years))
plt.bar(x,height=baokao_nums, width=0.4)
plt,bar([i + 0.4 for i in x],luqu_nums, width=0.4)
plt.xticks([i + 0.2 for i in x ])