gpt4 book ai didi

Python的Matplotlib库图像复现学习

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 28 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Python的Matplotlib库图像复现学习由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

Python的Matplotlib库图像复现学习

?
1
2
3
4
5
6
7
8
9
10
11
12
13
from pylab import *
n = 256
x = np.linspace( - np.pi,np.pi,n,endpoint = true)
y = np.sin( 2 * x)
plt.axes([ 0.025 , 0.025 , 0.95 , 0.95 ])
plt.plot (x, y + 1 , color = 'blue' , alpha = 1.00 )
plt.fill_between(x, 1 ,y + 1 ,color = 'b' ,alpha = . 25 )
plt.plot (x, y - 1 , color = 'blue' , alpha = 1.00 )
plt.fill_between(x, - 1 ,y - 1 ,(y - 1 )> - 1 ,color = 'b' ,alpha = . 25 )
plt.fill_between(x, - 1 ,y - 1 ,(y - 1 )< - 1 ,color = 'r' ,alpha = . 25 )
plt.xticks([])
plt.yticks([])
plt.show()

Python的Matplotlib库图像复现学习

?
1
2
3
4
5
6
7
8
9
10
11
12
from pylab import *
n = 1024
x = np.random.normal( 0 , 1 ,n)
y = np.random.normal( 0 , 1 ,n)
t = np.arctan2(y,x)
plt.axes([ 0.025 , 0.025 , 0.95 , 0.95 ])
plt.scatter(x,y,s = 60 ,c = t,alpha = . 5 )
plt.xlim( - 1.5 , 1.5 )
plt.ylim( - 1.5 , 1.5 )
plt.xticks([])
plt.yticks([])
plt.show()

Python的Matplotlib库图像复现学习

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from pylab import *
n = 12
x = np.arange(n)
y1 = ( 1 - x / float (n)) * np.random.uniform( 0.5 , 1.0 ,n)
y2 = ( 1 - x / float (n)) * np.random.uniform( 0.5 , 1.0 ,n)
 
plt.bar(x, + y1, facecolor = '#9999ff' , edgecolor = 'white' )
plt.bar(x, - y2, facecolor = '#ff9999' , edgecolor = 'white' )
for x,y in zip (x,y1):
     plt.text(x, y + 0.05 , '%.2f' % y, ha = 'center' , va = 'bottom' )
 
for x1,y1 in zip (x,y2):
     plt.text(x1, - y1 - 0.05 , '%.2f' % y1, ha = 'center' , va = 'top' )
 
plt.xlim( - . 5 ,n),plt.xticks([])
plt.ylim( - 1.25 , + 1.25 ),plt.yticks([])
plt.show()

Python的Matplotlib库图像复现学习

?
1
2
3
4
5
6
7
8
9
10
11
12
13
from pylab import *
def f(x,y):
     return ( 1 - x / 2 + x * * 5 + y * * 3 ) * np.exp( - x * * 2 - y * * 2 )
n = 256
x = np.linspace( - 3 , 3 ,n)
y = np.linspace( - 3 , 3 ,n)
x,y = np.meshgrid(x,y)
plt.axes([ 0.025 , 0.025 , 0.95 , 0.95 ])
plt.contourf(x,y,f(x,y), 8 , alpha = . 75 , cmap = plt.cm.hot)
c = plt.contour(x, y, f(x,y), 8 , colors = 'black' , linewidth = . 5 )
plt.clabel(c,inline = 1 ,fontsize = 10 )
plt.xticks([]),plt.yticks([])
plt.show()

Python的Matplotlib库图像复现学习

?
1
2
3
4
5
6
7
8
9
10
11
from pylab import *
def f(x,y): return ( 1 - x / 2 + x * * 5 + y * * 3 ) * np.exp( - x * * 2 - y * * 2 )
n = 10
x = np.linspace( - 3 , 3 , 4 * n)
y = np.linspace( - 3 , 3 , 3 * n)
x,y = np.meshgrid(x,y)
z = f(x,y)
plt.axes([ 0.025 , 0.025 , 0.95 , 0.95 ])
plt.imshow(z,interpolation = 'bicubic' ,cmap = 'bone' ,origin = 'lower' )
plt.colorbar(shrink = . 92 )
plt.xticks([]), plt.yticks([])

Python的Matplotlib库图像复现学习

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure()
ax = axes3d(fig)
x = np.arange( - 4.0 , 4.0 , 0.25 )
y = np.arange( - 4.0 , 4.0 , 0.25 )
x,y = np.meshgrid(x,y)
z = np.sin(np.sqrt(x * * 2 + y * * 2 ))
surf = ax.plot_surface(x,y,z,
  rstride = 1 ,
  cstride = 1 ,
  cmap = plt.get_cmap( 'rainbow' ))
ax.contourf(x,y,z,zdir = 'z' ,offset = - 2 ,cmap = plt.cm.hot)
ax.set_zlim( - 2 , 2 )
fig.colorbar(surf,shrink = 0.5 ,aspect = 8 )

总结

本篇文章就到这里了,希望能给你带来帮助,也希望您能够多多关注我的更多内容.

原文链接:https://blog.csdn.net/qq_41634258/article/details/119789922 。

最后此篇关于Python的Matplotlib库图像复现学习的文章就讲到这里了,如果你想了解更多关于Python的Matplotlib库图像复现学习的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com