Ⅰ 利用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虚线的长度