1.python turtle画4个同心圆方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
importturtle
#draw first circle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
#draw second circle
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
#draw third circle
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.circle(100)
#draw fourth circle
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(50)
画笔的坐标默认在0,0,就以它为圆心。
因为turtle画圆的时候是从圆的底部开始画的,所以需要找到四个圆底部的坐标
比如:
第一个半径为200的圆,底部为(0,-200)
第二个半径为150的圆,底部为(0,-150)
第三个半径为100的圆,底部为(0,-100)
第四个半径为 50的圆,底部为(0, -50)
画的时候按下面的步骤:
1. 抬起画笔:turtle.penup()
2. 移动到相应坐标:turtle.goto(坐标)
3. 放下画笔:turtle.pendown()
4. 画圆:turtle.circle(半径)
效果如下图所示:
2.如何使用Python绘制饼图
01首先我们需要在Excel文件中准备好饼图的数据,如下图所示02接下来我们打开Pycharm,新建Python文件,导入Python的pandas库,利用pandas将Excel数据加载到缓存中,如下图所示03然后我们在导入pyplot库,运用pyplot库的pie进行饼图的绘制,如下图所示04接着运行程序以后我们就可以看到一张如下图所示的饼图了,但是四周的名称和Excel中的还是不太一样,接下来修改四周的名称05我们在运用pandas库加载Excel数据文件的时候加上index_col属性即可,如下图所示06这次在运行程序我们就可以看到饼图四周的名称和Excel中的一样了,如下图所示07接着我们在运用pyplot中的title和ylable设置饼图的标题和Y坐标轴的名称,如下图所示08最后运行文件就可以看到下面这个信息比较齐全的饼图了,如下图所示,到这里用Python绘制饼图就结束了End。
3.如何用python turtle画一个中国象棋的棋盘
#绘制棋盘,每个格子50 import turtle t=turtle.Pen() bs=50#画直线 def line(x,y,z): t.penup() t.goto(x,y) t.pendown() t.fd(z)#两点直线 def any(a,b,c,d): t.penup() t.goto(a,b) t.pendown() t.goto(c,d)#画L型 def typeL(x,y): t.penup() t.goto(x-bs*0.25, y+bs*0.075) t.pendown() t.goto(x-bs*0.075, y+bs*0.075) t.goto(x - bs*0.075, y + bs*0.25) t.penup() t.goto(x - bs*0.25, y - bs*0.075) t.pendown() t.goto(x - bs*0.075, y - bs*0.075) t.goto(x - bs*0.075, y - bs*0.25) t.penup() t.goto(x+bs*0.25, y+bs*0.075) t.pendown() t.goto(x+bs*0.075, y+bs*0.075) t.goto(x + bs*0.075, y + bs*0.25) t.penup() t.goto(x + bs*0.25, y - bs*0.075) t.pendown() t.goto(x + bs*0.075, y - bs*0.075) t.goto(x + bs*0.075, y - bs*0.25)#画半L型 def typehL(x,y,z): if(z=='l'): t.penup() t.goto(x-bs*0.25, y+bs*0.075) t.pendown() t.goto(x-bs*0.075, y+bs*0.075) t.goto(x - bs*0.075, y + bs*0.25) t.penup() t.goto(x - bs*0.25, y - bs*0.075) t.pendown() t.goto(x - bs*0.075, y - bs*0.075) t.goto(x - bs*0.075, y - bs*0.25) if(z=='r'): t.penup() t.goto(x + bs*0.25, y + bs*0.075) t.pendown() t.goto(x + bs*0.075, y + bs*0.075) t.goto(x + bs*0.075, y + bs*0.25) t.penup() t.goto(x + bs*0.25, y - bs*0.075) t.pendown() t.goto(x + bs*0.075, y - bs*0.075) t.goto(x + bs*0.075, y - bs*0.25)#画横线 p=bs*4.5 while(p>=-bs*4.5): line(-bs*4,p,bs*8) p=p-bs any(bs*4,bs*4.5,bs*4,-bs*4.5) any(-bs*4,bs*4.5,-bs*4,-bs*4.5) t.right(90) q=-bs*3 while(q # -*- coding: utf-8 -*- from PIL import Image import ImageDraw # 打开图像 img = Image.open('i.jpg') img_d = ImageDraw.Draw(img) # 两个参数, 前面是 x,y 坐标,后面是 颜色 img_d.line(((0, 0), img.size), (0, 0, 0)) # 保存图片 img.save('ii.jpg')自己看看 PIL库 吧 亲,我好想回答过你的问题,matplotlib本身没有Venn图的函数,需要安装库matplotlib-venn,安装之前需要先确保具有numpy, scipy, matplotlib.这三个库。 安装方法: easy_install matplotlib-venn代码示例: set1 = set(['A', 'B', 'C', 'D']) set2 = set(['B', 'C', 'D', 'E']) set3 = set(['C', 'D',' E', 'F', 'G']) venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3')) plt.show() 转载请注明出处代码入门网 » python画相位图(pythonturtle画4个同心圆方法)4.如何使用python在一张图片上画左上角到右下角的对角线
5.怎么在 python中用matplotlib画韦恩图