用python画龙猫的代码(龙猫画图)
用python代码绘图?
python中subplot的用法
subplot是python中子图的绘制,这里主要介绍如何排布子图与极坐标图的绘制。
具体用法,需要搜索网上内容,再结合自己的情况修改参数即可。
Python作图程序
实战小程序:画出y=x^3的散点图
样例代码如下:
[python]?view plain?copy
#coding=utf-8
import?pylab?as?y????#引入pylab模块
x?=?y.np.linspace(-10,?10,?100)??#设置x横坐标范围和点数
y.plot(x,?x*x*x,'or')??#生成图像
ax?=?y.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',?0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',?0))
ax.set_yticks([-1000,?-500,?500,?1000])
y.xlim(x.min()?,?x.max()?)?#将横坐标设置为x的最大值和最小值
y.show()?#显示图像
[python]?view plain?copy
import?pylab?as?y
程序中引入的pylab属于matplotlib的一个模块,将其名字用y代替,其中包括了许多NumPy和pyplot模块中常用的函数,方便用户快速进行计算和绘图,十分适合在IPython交互式环境中使用。
[python]?view plain?copy
y.np.linspace(-10,?10,?100)
此为numpy中的一个函数,返回的是等间距的值,numpy.linspace(a,b,c):a指的是开始位置,b表示的是结束位置,c表示产生点的个数(默认为50)
举例:
[python]?view plain?copy
?np.linspace(2.0,?3.0,?num=5)
array([?2.??,??2.25,??2.5?,??2.75,??3.??])
[python]?view plain?copy
y.plot(x,?x*x*x,'or')??#生成图像
后面加上‘o'表示为散点图
'r'可设置颜色为红色,基本上和matlab的操作很像。
[python]?view plain?copy
y.xlim(x.min(),?x.max())
这条语句使用了xlim函数,将横坐标设置为x的大小
怎么用python绘图
你可以使用numpy和matplotlab这两个库来实现的你功能。
你的图可以参考:
import?matplotlib
from?numpy.random?import?randn
import?matplotlib.pyplot?as?plt
from?matplotlib.ticker?import?FuncFormatter
def?to_percent(y,?position):
????#?Ignore?the?passed?in?position.?This?has?the?effect?of?scaling?the?default
????#?tick?locations.
????s?=?str(100?*?y)
????#?The?percent?symbol?needs?escaping?in?latex
????if?matplotlib.rcParams['text.usetex']?==?True:
????????return?s?+?r'$\%$'
????else:
????????return?s?+?'%'
x?=?randn(5000)
#?Make?a?normed?histogram.?It'll?be?multiplied?by?100?later.
plt.hist(x,?bins=50,?normed=True)
#?Create?the?formatter?using?the?function?to_percent.?This?multiplies?all?the
#?default?labels?by?100,?making?them?all?percentages
formatter?=?FuncFormatter(to_percent)
#?Set?the?formatter
plt.gca().yaxis.set_major_formatter(formatter)
plt.show()
最主要的就是x轴和y轴的处理,我按照对数算了一下你提供的数据,好像和这个图效果不一样。
如果解决了您的问题请采纳!
如果未解决请继续追问
Python语言画图
1)首先Python画图与WING IDE无关,最简单的是使用Tkinter画图
2)画出单词有很多方法,最笨的是用划线方式一笔一笔的画。其次是直接输出文本,但意义不大。另外一种方法是调用图片,你可以在图片上任意画好东西后显示出来。
3)代码示例:(这个例子就画了个简单的字母P)
from Tkinter import *
root=Tk()
root.title('Drawing Example')
canvas=Canvas(root,width=200,height=160,bg='white')
canvas.create_line(10,10,100,70)
canvas.create_line(10,10,40,10)
canvas.create_line(40,10,40,40)
canvas.create_line(10,40,40,40)
canvas.pack()
root.mainloop()
有大神可以用python的turtle模块画图吗,求解
from turtle import*
pensize(4)
penup()
fd(150)
right(90)
fd(200)
pendown()
seth(100)
fd(150)
seth(31)
circle(130,300)
seth(170)
fd(80)#shou
seth(85)
fd(30)#qiang
left(90)#qiang
fd(120)#qiang
left(90)#qiang
fd(40)#qiang
left(90)#qiang
fd(80)#qiang
right(90)
fd(45)
left(90)
fd(40)
left(90)
fd(21)
penup()
fd(30)
pendown()
seth(100)
circle(20,290)
seth(340)
fd(90)
seth(270)
fd(100)
penup()
seth(90)
fd(250)
pendown()
pensize(20)
seth(270)
fd(7)
penup()
seth(0)
fd(100)
pendown()
seth(90)
fd(7)
penup()