‘壹’ 怎么用python绘图
你可以使用numpy和matplotlab这两个库来实现的你功能。
你的图可以参考:
http://matplotlib.org/examples/pylab_examples/histogram_percent_demo.html
importmatplotlib
fromnumpy.randomimportrandn
importmatplotlib.pyplotasplt
frommatplotlib.tickerimportFuncFormatter
defto_percent(y,position):
#Ignorethepassedinposition.
#ticklocations.
s=str(100*y)
#
ifmatplotlib.rcParams['text.usetex']==True:
returns+r'$\%$'
else:
returns+'%'
x=randn(5000)
#Makeanormedhistogram.It'llbemultipliedby100later.
plt.hist(x,bins=50,normed=True)
#_percent.Thismultipliesallthe
#defaultlabelsby100,makingthemallpercentages
formatter=FuncFormatter(to_percent)
#Settheformatter
plt.gca().yaxis.set_major_formatter(formatter)
plt.show()
最主要的就是x轴和y轴的处理,我按照对数算了一下你提供的数据,好像和这个图效果不一样。
如果解决了您的问题请采纳!
如果未解决请继续追问
‘贰’ 如何用Python绘画日本国旗
使用Python自己的绘图工具即可,turtle。
#encoding:utf-8
#python3.6
importturtle
defdraw_japan_flag():
#日本国旗为“太阳旗”,呈长方形,长与宽之比为3∶2。旗面为白色,正中有一轮红日。
#红日半径
r=150
#画布尺寸(宽,高)
turtle.screensize(900,600)
#设置显示窗口像素
turtle.setup(width=900,height=600)
#移动画笔起点
turtle.penup()
turtle.goto(0,-r)
turtle.pendown()
#设置画笔属性
turtle.pensize(5)
turtle.pencolor("red")
turtle.fillcolor("red")
#绘制速度,1~10个不同速度等级,小于1或者大于10立即绘制
turtle.speed(0)
#开始绘制红日
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
turtle.mainloop()
if__name__=="__main__":
draw_japan_flag()
‘叁’ python按钮如何连接到绘画图窗
第一,启动Python自带的集中开发环境IDLE,然后点击File-->New File,并在脚本框中输入如下代码,用于创建窗口和按钮。
from tkinter import * # 从tkinter库中导入所有函数
window1=Tk() # 创建一个窗口
window1.title('test1') # 设置窗口标题
window1.geometry('500x500+100+100') # 设置窗口大小x和左顶距离+
def Jason(): # 创建一个函数
print('Come on,baby')
button1=Button(window1,text='点我啊',command=Jason) # 设置按钮属性
button1.pack() # 设置显示按钮
window1.mainloop() # 设置窗口循环显示
Python创建窗口按钮和绘制画布直线
第二,保存和运行上述脚本,得到如下窗口和窗口中的按钮“点我啊”。
Python创建窗口按钮和绘制画布直线
第三,点击“点我啊”按钮,会在IDLE中显示“Come on, baby”.
Python创建窗口按钮和绘制画布直线
第四,在IDLE中再次点击File-->New File,并在脚本中输入如下代码,用于创建窗口画布和在画布上绘制直线。
from tkinter import *
window1=Tk()
window1.title('test2')
canvas1=Canvas(window1,width=500,height=500,bg='pink') # 设置画布
canvas1.pack() # 显示画布
# 利用create_line()在画布上绘制直线
canvas1.create_line(100,100,400,100,width=5,fill='red')
canvas1.create_line(100,200,400,200,width=15,fill='green')
canvas1.create_line(100,300,400,300,width=35,fill='blue')
window1.mainloop()
Python创建窗口按钮和绘制画布直线
第五,保存和运行上述脚本,可以得到如下图形,画布中绘制了“红 绿 蓝”三条线。
Python创建窗口按钮和绘制画布直线
‘肆’ python可以画图吗
可以。画简单的图可以用turtle库,画数学函数要用matplotlib库。
‘伍’ 为什么python画封闭图形是黑色的
因为python默认是黑色,你可以根据自己需要去更改颜色
‘陆’ python画图
matplotlib就可以,看他示例文件里动画那个文件夹。
‘柒’ python 如何绘画一个圆柱体,求详细代码。
defellipse(a,b):
return[[a*math.cos(i*math.pi/180),b*math.sin(i*math.pi/180)]foriinrange(0,360)]
if__name__=="__main__":
l=ellipse(150,80)
turtle.up()
turtle.setpos(150,80)
turtle.down()
for(x,y)inl:
turtle.setpos(x,y)
turtle.setpos(x,y+100)
for(x,y)inl:
turtle.setpos(x,y+100)
turtle.up()
turtle.setpos(-150,90)
turtle.down()
turtle.setpos(x-300,y+100)
turtle.setpos(x-300,y)
turtle.done()
‘捌’ 为什么用python画图总是偏右画
python沿画笔的方向画线用forward()函数。
forward()函数能使画笔前进,比如沿画笔方向画100像素的直线,代码如下所示:turtle.forward(100)。
‘玖’ 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这个怎么绘图
importmatplotlib.pyplotasplt
#plt.rcParams['font.sas-serig']=['SimHei']#用来正常显示中文标签
x=['第一产业','第二产业','第三产业',]
plt.ylabel('项目')
plt.xlabel(x,fontproperties="SimHei")#或者这样来显示中文
x_=['1','2','3']
y=[24171.0,23170,29636]
y1=[22790,23099,31364]
y2=[21919,22693,32839]
y3=[21496,22350,33757]
y4=[20944,21824,34872]
plt.xticks([])#隐藏坐标
plt.plot(x_,y,x_,y1,x_,y2,x_,y3,x_,y4)
plt.show()
底下的那个坐标我不知道具体多少,所以做了个大概的以供参考哦