import matplotlib.pyplot as plt
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0,2*np.pi,100)y1,y2 = np.sin(x),np.cos(x)plt.plot(x,y1)plt.plot(x,y2)plt.title("sanjiaohanshu")plt.xlabel("x")plt.ylabel("y")plt.show()复制代码
name_list = ["A","B","C","D","E"]num_list = [1.6,0.5,7,3.4,9]plt.bar(range(len(num_list)),num_list,color="ygbrc",tick_label=name_list)plt.show()复制代码
# 堆叠柱状图name_list = ["A","B","C","D","E"]num_list = [1.6,0.5,7,3.4,9]num_list1 = [1,0.9,3.6,9,8]plt.bar(range(len(num_list)),num_list,label="boy",fc ="c")plt.bar(range(len(num_list1)),num_list1,label = "girl",fc="g")plt.legend()plt.show()复制代码
# 并列柱状图name_list = ["A","B","C","D","E"]num_list = [1.6,0.5,7,3.4,9]num_list1 = [1,0.9,3.6,9,8]x = list(range(len(num_list)))totle_width,n = 0.8,2width = totle_width/nplt.bar(x,num_list,width=width,label="boy",fc="y")for i in range(len(x)): x[i] = x[i]+widthplt.bar(x,num_list1,width=width,label="girl",fc="b")plt.legend()plt.show()复制代码
# 饼状图labels = "A","B","C","D","E"fracs = [15,25,10,67,66.4]# 凸显数据explode = [0,0,0.1,0.3,0]plt.axes(aspect=1)plt.pie(x=fracs,labels=labels,explode=explode,autopct="%3.4f%%",shadow=True,startangle=90)plt.show()复制代码
# 实时绘图# ax = []# ay = []# plt.ion()# for i in range(100):# ax.append(i)# ay.append(i**2)# # 清除# plt.clf()# plt.plot(ax,ay)# plt.pause(0.1)# plt.ioff()# plt.show()复制代码
from mpl_toolkits.mplot3d import Axes3D# 三维绘图x = np.random.normal(0,1,100)y = np.random.normal(0,1,100)z = np.random.normal(0,1,100)fig = plt.figure()ax = Axes3D(fig)ax.scatter(x,y,z)plt.show()复制代码
#OpenCV简单使用
import cv2 img = cv2.imread("pic.jpg")# img = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)# cv2.imshow("image",img)# cv2.waitKey(0)# cv2.destroyAllWindows()#画线green = (0,255,0)# cv2.line(img,(0,0),(300,300),green,3)# cv2.imshow("image",img)# cv2.waitKey(0)# cv2.destroyAllWindows()#画矩形# cv2.rectangle(img,(50,100),(150,200),green,5)# cv2.imshow("image",img)# cv2.waitKey(0)# cv2.destroyAllWindows()#画圆cv2.circle(img,(150,150),100,green,3)cv2.imshow("image",img)cv2.waitKey(0)cv2.destroyAllWindows()cv2.imwrite("tt.jpg",img)复制代码