导航:首页 > 编程语言 > python图案思维

python图案思维

发布时间:2023-06-03 18:13:36

python可以画出哪些简单图形

一、画一朵花+签名
代码如下:
# -*- coding:utf-8 -*-
#画一朵花+签名
import turtle
turtle.color('red','green')
turtle.pensize(5)
turtle.goto(0,0)
turtle.speed(10)
for i in range(15):
turtle.forward(100)
turtle.right(150)
turtle.up()

turtle.goto(150,-120)
turtle.color('black')
turtle.write("xxx" )
turtle.up()

turtle.goto(160,-140)
turtle.color('black')
turtle.write("2018 年 1 月 10 日" )
turtle.up()

turtle.goto(240,-160)
turtle.color('black')
turtle.write("." )
turtle.done()

二、画五角星脸+签名
代码如下:
# -*- coding:utf-8 -*-
#画五角星脸+签名
import turtle
turtle.color('red','green')
turtle.pensize(5)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.up()
turtle.goto(150,120)
turtle.down()
turtle.color('red','green')
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.up()
turtle.goto(-80,90)
turtle.down()
turtle.color('red','green')
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.up()
turtle.goto(150,-120)
turtle.color('black')
turtle.write("xxx" )
turtle.up()
turtle.goto(160,-140)
turtle.color('black')
turtle.write("2018 年 1 月 7 日" )
turtle.up()
turtle.goto(240,-160)
turtle.color('black')
turtle.write("." )
turtle.done()

Ⅱ 如何用python绘制各种图形

1.环境

系统:windows10

python版本:python3.6.1

使用的库:matplotlib,numpy

2.numpy库产生随机数几种方法

import numpy as np
numpy.random

rand(d0,d1,...,dn)

In [2]: x=np.random.rand(2,5)

In [3]: x
Out[3]:
array([[ 0.84286554, 0.50007593, 0.66500549, 0.97387807, 0.03993009],
[ 0.46391661, 0.50717355, 0.21527461, 0.92692517, 0.2567891 ]])

randn(d0,d1,...,dn)查询结果为标准正态分布

In [4]: x=np.random.randn(2,5)

In [5]: x
Out[5]:
array([[-0.77195196, 0.26651203, -0.35045793, -0.0210377 , 0.89749635],
[-0.20229338, 1.44852833, -0.10858996, -1.65034606, -0.39793635]])

randint(low,high,size)

生成low到high之间(半开区间 [low, high)),size个数据

In [6]: x=np.random.randint(1,8,4)

In [7]: x
Out[7]: array([4, 4, 2, 7])

random_integers(low,high,size)

生成low到high之间(闭区间 [low, high)),size个数据

In [10]: x=np.random.random_integers(2,10,5)

In [11]: x
Out[11]: array([7, 4, 5, 4, 2])

3.散点图

x x轴
y y轴
s 圆点面积
c 颜色
marker 圆点形状
alpha 圆点透明度#其他图也类似这种配置
N=50# height=np.random.randint(150,180,20)# weight=np.random.randint(80,150,20)
x=np.random.randn(N)
y=np.random.randn(N)
plt.scatter(x,y,s=50,c='r',marker='o',alpha=0.5)
plt.show()

8.箱型图

import matplotlib.pyplot as pltimport numpy as npdata=np.random.normal(loc=0,scale=1,size=1000)#sym 点的形状,whis虚线的长度plt.boxplot(data,sym="o",whis=1.5)plt.show()
#sym 点的形状,whis虚线的长度

Ⅲ python编程题:字母图案 输入任意字母,输出图案

代码:

c=input('输入字母:')

m=ord(c)

n=m-ord('A')

for i in range(-n,n+1):

t=i if i>0 else -i

print(t*' '+4*chr(m-t))

截图:

Ⅳ 如何用Python画各种着名数学图案

如何用Python画各种着名数学图案 | 附图+代码

用Python绘制着名的数学图片或动画,展示数学中的算法魅力。
Mandelbrot 集

'''
A fast Mandelbrot set wallpaper renderer

reddit discussion:
'''
importnumpy asnp
fromPILimportImage
fromnumba importjit

MAXITERS=200
RADIUS=100

@jit
defcolor(z, i):
v =np.log2(i +1-np.log2(np.log2(abs(z)))) /5
ifv <1.0:
returnv**4, v**2.5, v
else:
v =max(0, 2-v)
returnv, v**1.5, v**3

@jit
defiterate(c):
z =0j
fori inrange(MAXITERS):
ifz.real*z.real +z.imag*z.imag >RADIUS:
returncolor(z, i)
z =z*z +c
return0, 0,0

defmain(xmin, xmax, ymin, ymax, width, height):
x =np.linspace(xmin, xmax, width)
y =np.linspace(ymax, ymin, height)
z =x[None, :] +y[:, None]*1j
red, green, blue =np.asarray(np.frompyfunc(iterate, 1, 3)(z)).astype(np.float)
img =np.dstack((red, green, blue))
Image.fromarray(np.uint8(img*255)).save('mandelbrot.png')

if__name__=='__main__':
main(-2.1, 0.8, -1.16, 1.16, 1200, 960)

阅读全文

与python图案思维相关的资料

热点内容
电影人狗叫 浏览:506
取消压缩管理的公司 浏览:116
打真军的电影豆瓣 浏览:168
特斯拉app超级充电桩如何使用 浏览:422
男人怀孕电影袋鼠男人 浏览:507
如何删去应用加密 浏览:468
服从命令听指挥陌千依小说 浏览:761
《赤足惊魂》电影介绍 浏览:359
ic卡内数据如何传到服务器 浏览:21
安卓系统如何更改托盘 浏览:403
许志安演的电影有哪些 浏览:824
odbc文件夹是什么 浏览:391
男主用铁链囚禁女主的小说 浏览:914
sift算法harris算法 浏览:241
python命令行模式 浏览:459
新妈妈韩国电影中的辅导老师是谁 浏览:389
php邮箱验证代码 浏览:404
光猫伪装命令 浏览:175
安卓高端机为什么都用曲屏 浏览:419
老电影大全 战争片 浏览:971