導航:首頁 > 編程語言 > 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圖案思維相關的資料

熱點內容
珠海存儲伺服器地址怎麼找 瀏覽:413
md5演算法字元串長度 瀏覽:4
可以二次虛化的雲伺服器 瀏覽:779
思科2500編程器固件 瀏覽:235
php開發桌面應用程序 瀏覽:904
支付寶app哪裡可以加油 瀏覽:71
路由器ttl刷編程器固件 瀏覽:719
縱向加密密鑰協商狀態時間 瀏覽:851
mc花雨庭伺服器有些什麼 瀏覽:809
linux製作網頁 瀏覽:19
xlsx加密忘記了怎麼辦 瀏覽:999
app湖北農信怎麼解約 瀏覽:426
在線編程教育項目 瀏覽:759
電信采購5萬台伺服器干什麼用 瀏覽:200
騰訊雲伺服器登錄地址 瀏覽:988
程序員在地鐵上寫字 瀏覽:555
解壓包未知文件格式怎麼辦 瀏覽:578
程序員破壞資料庫 瀏覽:331
sh格式如何編譯 瀏覽:344
虛擬伺服器雲主機哪個好 瀏覽:98