『壹』 怎麼用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()
底下的那個坐標我不知道具體多少,所以做了個大概的以供參考哦