python绘制立体玫瑰花
㈠ python怎么画玫瑰花
操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令
1. 运动命令:
forward(degree) #向前移动距离degree代表距离
backward(degree) #向后移动距离degree代表距离
right(degree) #向右移动多少度
left(degree) #向左移动多少度
goto(x,y) #将画笔移动到坐标为x,y的位置
stamp() #复制当前图形
speed(speed) #画笔绘制的速度范围[0,10]整数
2. 画笔控制命令:
down() #移动时绘制图形,缺省时也为绘制
up() #移动时不绘制图形
pensize(width) #绘制图形时的宽度
color(colorstring) #绘制图形时的颜色
fillcolor(colorstring) #绘制图形的填充颜色
fill(Ture)
fill(false)
lucy : 梦想照进现实;露茜;青春风采;
draw_flower1.py
[python]view plain
#-*-coding:cp936-*-
importturtle
importmath
defp_line(t,n,length,angle):
"""Drawsnlinesegments."""
foriinrange(n):
t.fd(length)
t.lt(angle)
defpolygon(t,n,length):
"""Drawsapolygonwithnsides."""
angle=360/n
p_line(t,n,length,angle)
defarc(t,r,angle):
"""."""
arc_length=2*math.pi*r*abs(angle)/360
n=int(arc_length/4)+1
step_length=arc_length/n
step_angle=float(angle)/n
#Beforestartingreces,makingaslightleftturn.
t.lt(step_angle/2)
p_line(t,n,step_length,step_angle)
t.rt(step_angle/2)
defpetal(t,r,angle):
"""Drawsa花瓣usingtwoarcs."""
foriinrange(2):
arc(t,r,angle)
t.lt(180-angle)
defflower(t,n,r,angle,p):
"""Drawsaflowerwithnpetals."""
foriinrange(n):
petal(t,r,angle)
t.lt(p/n)
defleaf(t,r,angle,p):
"""Drawsa叶子andfillit."""
t.begin_fill()#Beginthefillprocess.
t.down()
flower(t,1,40,80,180)
t.end_fill()
defmain():
window=turtle.Screen()#creatascreen
window.bgcolor("blue")
lucy=turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(5)
lucy.speed(0)
#Drawingflower
flower(lucy,7,60,100,360)
#Drawingpedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200)
#Drawingleaf
lucy.rt(270)
lucy.color("green")
leaf(lucy,40,80,180)
lucy.ht()
window.exitonclick()
main()
㈡ PYThon画玫瑰如何确定像素大小
在蚂薯 Python 中画玫瑰图时,要确定像素大小,可以使用 matplotlib 库中的 figure 函数和 subplots 函数。其中,figure 函数用于创建一个新的画布,如物好subplots 函数用于在画布上创建一个子图。通过设置 figsize 参数,可以控制画布的大小,从而确定像素大小。例如:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8, 8)) # 创建一个大小为 8x8 英寸的画布
ax = fig.subplots() # 在画布上创建一个子图
# 在子图上渣铅绘制玫瑰图
# ...
plt.show() # 显示图形
在这个例子中,创建了一个大小为 8x8 英寸的画布,通过 subplots 函数在画布上创建了一个子图,并在子图上绘制了玫瑰图。根据画布的大小和显示器的分辨率,可以确定像素大小。
㈢ 用Python matplotlib 怎么画风向玫瑰图 能给出程序的
需要提前安装windrose模块
importmatplotlib.cmascm
fromnumpy.randomimportrandom
fromnumpyimportarange
ws=random(500)*6
wd=random(500)*360
#...
defnew_axes():
fig=plt.figure(figsize=(8,8),dpi=80,facecolor='w',edgecolor='w')
rect=[0.1,0.1,0.8,0.8]
ax=WindroseAxes(fig,rect,axisbg='w')
fig.add_axes(ax)
returnax
#...andadjustthelegendbox
defset_legend(ax):
l=ax.legend(shadow=True,bbox_to_anchor=[-0.1,0],loc='lowerleft')
plt.setp(l.get_texts(),fontsize=10)
ax=new_axes()
ax.bar(wd,ws,normed=True,opening=0.8,edgecolor='white')
set_legend(ax)
plt.show()
㈣ 怎么用python画玫瑰花,求大神贴代码,感激不尽
importturtle
#设置初始位置
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
#花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10,180)
turtle.circle(25,110)
turtle.left(50)
turtle.circle(60,45)
turtle.circle(20,170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30,110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90,70)
turtle.circle(30,150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80,90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150,80)
turtle.left(50)
turtle.circle(150,90)
turtle.end_fill()
#花瓣1
turtle.left(150)
turtle.circle(-90,70)
turtle.left(20)
turtle.circle(75,105)
turtle.setheading(60)
turtle.circle(80,98)
turtle.circle(-90,40)
#花瓣2
turtle.left(180)
turtle.circle(90,40)
turtle.circle(-80,98)
turtle.setheading(-83)
#叶子
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80,90)
turtle.right(90)
turtle.circle(-80,90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
#叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80,90)
turtle.left(90)
turtle.circle(80,90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200,60)
运行结果:
㈤ 用Python matplotlib 怎么画风向玫瑰图 能给出程序的
importnumpyasnp
importmatplotlib.pyplotasplt
N=20
theta=np.linspace(0.0,2*np.pi,N,endpoint=False)
radii=10*np.random.rand(N)
width=np.pi/4*np.random.rand(N)
ax=plt.subplot(111,projection='polar')
bars=ax.bar(theta,radii,width=width,bottom=0.0)
#Usecustomcolorsandopacity
forr,barinzip(radii,bars):
bar.set_facecolor(plt.cm.jet(r/10.))
bar.set_alpha(0.5)
plt.show()
差不多上面代码的原理,具体的自己照专着官方文属档改