Ⅰ 利用python如何製作好玩的GIF動圖詳解
import sysimport numpy as npimport matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimation fig, ax = plt.subplots()fig.set_tight_layout(True) # 詢問圖形在屏幕上的大小和DPI(每英寸點數)# 注意當把圖形保存為文件時,需要為此單獨再提供一個DPIprint('fig size: {0} DPI, size in inches {1}'.format( fig.get_dpi(), fig.get_size_inches())) # 繪制一個保持不變(不會被重新繪制)的散點圖以及初始直線x = np.arange(0, 20, 0.1)ax.scatter(x, x + np.random.normal(0, 3.0, len(x)))line, = ax.plot(x, x - 5, 'r-', linewidth=2) def update(i): label = 'timestep {0}'.format(i) print(label)# 更新直線和軸(用一個新X軸標簽) # 以元組形式返回這一幀需要重新繪制的物體 line.set_ydata(x - 5 + i) ax.set_xlabel(label) return line, ax if __name__ == '__main__': # 會為每一幀調用Update函數 # 這里FunAnimation設置一個10幀動畫,每幀間隔200ms anim = FuncAnimation(fig, update, frames=np.arange(0, 10), interval=200) if len(sys.argv) > 1 and sys.argv[1] == 'save': anim.save('line.gif', dpi=80, writer='imagemagick') else: # Plt.show()會一直循環動畫 plt.show()
Ⅱ 怎麼用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如何識別表情包並回復文字,操作方法如下。
設備:聯想電腦
系統:win8
軟體:Python
1、首先通過pip install emoji,來安裝emoji包。
Ⅳ 可以用Python代碼繪制一個人像嗎
可以的。
基本思路:選好畫板大小,設置好畫筆顏色,粗細,定位好位置,依次畫鼻子,頭、耳朵、眼睛、腮、嘴、身體、手腳、,完事。
都知道,turtle 是 python 內置的一個比較有趣味的模塊,俗稱海龜作圖,它是基於 tkinter 模塊打造,提供一些簡單的繪圖工具。
Ⅳ python區域網聊天室怎麼編寫表情代碼,用什麼方式打開,需要什麼插件嗎
要VB我給你代碼,Python不會
Ⅵ python如何自動生成表情包
"""
注意asd4.jpg,asd5.jpg,draw.text,Python生成的表情包.jpg
和本執行文件.py均在一個目錄中。
"""
fromPILimportImage,ImageDraw,ImageFont
img=Image.open("asd4.jpg")
w,h=img.size
img=img.resize((w*2,h*2))#調整asd4尺寸
jgz=Image.open("asd5.jpg")
w,h=jgz.size
jgz=jgz.resize((w*1,h*1))#調整asd5尺寸
img.paste(jgz,(120,80))#調120,是左右移動asd5,調80大小是上下移動asd5
img.show()
draw=ImageDraw.Draw(img)
ttfront=ImageFont.truetype('simhei.ttf',50)#調整50大小是調字的大小
draw.text((165,160),"她是誰",fill=(0,0,0),font=ttfront)
#text(x,y)y調字上下移動,x調字左右."她是誰"可隨意改寫
img.show()
img.save("Python生成的表情包.jpg")
Ⅶ 怎麼用Python製作一個好玩炫酷的GIF動態圖
importsys
importnumpyasnp
importmatplotlib.pyplotasplt
frommatplotlib.animationimportFuncAnimation
fig,ax=plt.subplots()
fig.set_tight_layout(True)
#詢問圖形在屏幕上的大小和DPI(每英寸點數)
#注意當把圖形保存為文件時,需要為此單獨再提供一個DPI
print('figsize:{0}DPI,sizeininches{1}'.format(
fig.get_dpi(),fig.get_size_inches()))
#繪制一個保持不變(不會被重新繪制)的散點圖以及初始直線
x=np.arange(0,20,0.1)
ax.scatter(x,x+np.random.normal(0,3.0,len(x)))
line,=ax.plot(x,x-5,'r-',linewidth=2)
defupdate(i):
label='timestep{0}'.format(i)
print(label)
#更新直線和軸(用一個新X軸標簽)
#以元組形式返回這一幀需要重新繪制的物體
line.set_ydata(x-5+i)
ax.set_xlabel(label)
returnline,ax
if__name__=='__main__':
#會為每一幀調用Update函數
#這里FunAnimation設置一個10幀動畫,每幀間隔200ms
anim=FuncAnimation(fig,update,frames=np.arange(0,10),interval=200)
iflen(sys.argv)>1andsys.argv[1]=='save':
anim.save('line.gif',dpi=80,writer='imagemagick')
else:
#Plt.show()會一直循環動畫
plt.show()
可以生成下面這種圖
Ⅷ Python怎麼輸出太陽表情
可以使用Rich 製作太陽表情。它是一個 Python 庫,可以為您在終端中提供富文本和精美格式。Rich API可以很容易的在終端輸出添加各種顏色和不同風格。Rich 還可以繪制漂亮的表格,進度條,markdown,突出顯示語法的源代碼及回溯等等,不勝枚舉。Rich 適用於 Linux,OSX 和 Windows。真彩色/表情符號可與新的 Windows 終端一起使用,Windows 的經典終端僅限 8 種顏色。Rich 還可以與Jupyter 筆記本一起使用,而無需其他配置。有時候在代碼中加入一些有趣的操作可以使得友好度 UP 好幾個 LEVEL,正好了解到 Python 支持 emoji 表情的輸出,實現方式相當簡單。
Ⅸ 如何用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虛線的長度