电子商务网站开发技术,深圳互联网协会,私人20服务器,做网站广告公司1 说明#xff1a;1.1 是问答中的我的一个回答。1.1 因为问答中没有代码块的#xff0c;所以我改为这里写文章#xff0c;然后链接过去。1.2 4种方法#xff1a;turtle法、OpenCV法、pygame法和matplotlib法。2 turtle法#xff1a;2.1 代码#xff1a;#第1步#xff1a…1 说明1.1 是问答中的我的一个回答。1.1 因为问答中没有代码块的所以我改为这里写文章然后链接过去。1.2 4种方法turtle法、OpenCV法、pygame法和matplotlib法。2 turtle法2.1 代码#第1步导入模块import turtle as t#第2步初始化设置#窗口大小t.setup(800,800)#画笔颜色t.pencolor(green)#画笔粗细t.pensize(2.5)#第3步开始绘画#r300t.fd(300)#向左转向90本来方向是水平向右t.left(90)#这时候方向就是垂直向上#画圆r300,120°t.circle(300,120)#转角t.left(90)#走300r回到原点(圆点)t.fd(300)t.done()2.2 效果图3 OpenCV法3.1 代码注释版#cv2就是OpenCV#第1步导入模块import numpy as npimport cv2#第2步Create a black image#窗口或者空的图像的大小pic_wpic_h800#获取中心点坐标centerxyint(pic_w/2)#产生一个空的图像img np.zeros((pic_w,pic_h,3), np.uint8)#第3步画椭圆来画扇形#cv2.ellipse(img, center, axes, angle, startAngle, endAngle, #color[, thickness[, lineType[, shift]]])#重要参数img: 图片center椭圆中心(x,y) 比如(256,256)axesx/y轴的长度 比如(100,50)angleangle--椭圆的旋转角度0#角度是以顺时针方向计算的startAnglestartAngle--椭圆的起始角度90endAngleendAngle--椭圆的结束角度180color: 颜色#坐标点(centerxy,centerxy)代表窗口的中心点#270°开始顺时针180°停止img cv2.ellipse(img,(centerxy,centerxy),(100,50),0,270,180,(0,255,0),-1)cv2.imshow(image,img)cv2.waitKey(0)cv2.destroyAllWindows()3.2 效果图4 pygame法4.1 代码#注意pygame画扇形是通过画弧形来的一般弧形宽度为1#如果宽度等于半径就是扇形#第1步导入模块import pygame,sys,mathfrom pygame.locals import *#第2步初始化pygame.init()#窗口大小设置screen pygame.display.set_mode((600,500))#窗口标题名pygame.display.set_caption(sector扇形)#第3步循环while True: #退出设置pygame必须在循环中一开始就设立 for event in pygame.event.get(): if event.type in (KEYDOWN,QUIT): sys.exit() #背景颜色填充255,255,255白色 screen.fill((0,0,0)) #黑色 color 0,0,255 #蓝色 start_angle math.radians(0) end_angle math.radians(80) #注意width一般为1那就是弧形当等于rradius就是扇形 width 200 x 300 y 250 radius 200 #位置公式喜欢这样看得懂 position x - radius, y - radius, radius*2, radius*2 #利用画弧形函数 pygame.draw.arc(screen,color,position,start_angle,end_angle,width) pygame.display.update()4.2 图5 matplotlib法5.1 代码#利用饼图画扇形不显示其他#第1步导入模块import matplotlib.pyplot as plt#第2步定义画布fig plt.figure(figsize(8,6), dpi80)#第3步数据datax[10,20,40,20,10]#突出第3部分explode [0,0,0.1,0,0]#显示突出第3部分其余均为w白色colorx[w,w,r,w,w]#第4步作图设置标签突出显示块显示百分比#plt.pie(frac, labelslabels, explodeexplode, autopct%.1f%%,colorscolorx)#不显示其他部分plt.pie(datax,explodeexplode,colorscolorx)#标题名plt.title(扇形图)#图片展示plt.show()5.2 图喜欢不关注我不迷路。