Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Model Center   Code  
»áÔ±   
   
 
     
   
 ¶©ÔÄ
  ¾èÖú
PythonµÚÈý·½¿âmatplotlib£¨2D»æÍ¼¿â£©ÈëÃÅÓë½ø½×
 
  6379  次浏览      27
 2018-12-13 
 
±à¼­ÍƼö:
À´Ô´infoq£¬Í¨¹ý Matplotlib£¬¿ª·¢Õß¿ÉÒÔ½öÐèÒª¼¸ÐдúÂ룬±ã¿ÉÒÔÉú³É»æÍ¼£¬Ö±·½Í¼£¬¹¦ÂÊÆ×£¬ÌõÐÎͼ£¬´íÎóͼ£¬É¢µãͼµÈ¡£ÎÄÖÐÖ÷Òª½éÉÜÁËÔõôÑù»æÖÆÍ¼¡£

Matplotlib

Ò» ¼ò½é£º

MatplotlibÊÇÒ»¸öPython 2D»æÍ¼¿â£¬Ëü¿ÉÒÔÔÚ¸÷ÖÖÆ½Ì¨ÉÏÒÔ¸÷ÖÖÓ²¿½±´¸ñʽºÍ½»»¥Ê½»·¾³Éú³É³ö¾ßÓгö°æÆ·ÖʵÄͼÐΡ£ Matplotlib¿ÉÓÃÓÚPython½Å±¾£¬PythonºÍIPython shell£¬Jupyter±Ê¼Ç±¾£¬WebÓ¦ÓóÌÐò·þÎñÆ÷ºÍËĸöͼÐÎÓû§½çÃæ¹¤¾ß°ü

MatplotlibÊÔͼÈüòµ¥µÄÊÂÇé±äµÃ¸ü¼òµ¥£¬ÈÃÎÞ·¨ÊµÏÖµÄÊÂÇé±äµÃ¿ÉÄÜʵÏÖ¡£ Ö»Ð輸ÐдúÂë¼´¿ÉÉú³É»æÍ¼£¬Ö±·½Í¼£¬¹¦ÂÊÆ×£¬ÌõÐÎͼ£¬´íÎóͼ£¬É¢µãͼµÈ¡£ ÓйØÊ¾Àý£¬Çë²ÎÔÄʾÀýͼºÍËõÂÔͼ¿â¡£

ΪÁ˼òµ¥»æÍ¼£¬pyplotÄ£¿éÌṩÁËÀàËÆÓÚMATLABµÄ½çÃæ£¬ÌرðÊÇÓëIPython½áºÏʹÓÃʱ¡£ ¶ÔÓڸ߼¶Óû§£¬Äú¿ÉÒÔͨ¹ýÃæÏò¶ÔÏóµÄ½çÃæ»òMATLABÓû§ÊìϤµÄÒ»×麯ÊýÍêÈ«¿ØÖÆÏßÌõÑùʽ£¬×ÖÌåÊôÐÔ£¬ÖáÊôÐԵȡ£

¶þ Ïà¹ØÎĵµ£º

¹ÙÍø½Ì³ÌÎĵµ£ºhttps://matplotlib.org/users/index.html

¸÷¸öƽ̨µÄ°²×°½Ì³Ì£ºhttps://matplotlib.org/users/installing.html

Èý ÈëÃÅÓë½ø½×°¸Àý

1- ¼òµ¥Í¼ÐλæÖÆ

¸ù¾Ý×ø±êµã»æÖÆ£º

import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([3,5,7,6,2,6,10,15])
plt.plot(x,y,'r')# ÕÛÏß 1 x 2 y 3 color
plt.plot(x,y,'g',lw=10)# 4 line w
# ÕÛÏß ±ý×´ Öù×´
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([13,25,17,36,21,16,10,15])
plt.bar(x,y,0.2,alpha=1,color='b')# 5 color 4 ͸Ã÷¶È 3 0.9
plt.show()

´«Èë²ÎÊýÊÇnumpyÊý×éʱµÄЧ¹û£º

import numpy as np
import matplotlib.pyplot as plt
for i in range(0,15):
# 1 Öù״ͼ
dateOne = np.zeros([2])
dateOne[0] = i;
dateOne[1] = i;
y = np.zeros([2])
y[0] = 10
y[1] = 20
plt.plot(dateOne,y,'r',lw=8)
plt.show()

¸ù¾Ýº¯ÊýͼÏñ»æÖÆ£º

# -*- coding: utf-8 -*-
"""
¼òµ¥Í¼ÐλæÖÆ
"""
import matplotlib.pyplot as plt
import numpy as np
#´Ó-1-----1Ö®¼äµÈ¼ä¸ô²É66¸öÊý.Ò²¾ÍÊÇ˵Ëù»­³öÀ´µÄͼÐÎÊÇ66¸öµãÁ¬½ÓµÃÀ´µÄ
#×¢Ò⣺Èç¹ûµãÊý¹ýСµÄ»°»áµ¼Ö»­³öÀ´¶þ´Îº¯ÊýͼÏñ²»Æ½»¬
x = np.linspace(-1, 1,66)
# »æÖÆy=2x+1º¯ÊýµÄͼÏñ
y = 2 * x + 1
plt.plot(x, y)
plt.show()
# »æÖÆx^2º¯ÊýµÄͼÏñ
y = x**2
plt.plot(x, y)
plt.show()

2- figureµÄ¼òµ¥Ê¹ÓÃ

# -*- coding: utf-8 -*-
"""
figureµÄʹÓÃ
"""
import matplotlib.pyplot as plt
import numpy as np
#
x = np.linspace(-1, 1, 50)# figure 1
y1 = 2 * x + 1
plt.figure()
plt.plot(x, y1)# figure 2
y2 = x**2
plt.figure()
plt.plot(x, y2)# figure 3£¬Ö¸¶¨figureµÄ±àºÅ²¢Ö¸¶¨figureµÄ´óС, Ö¸¶¨ÏßµÄÑÕÉ«, ¿í¶ÈºÍÀàÐÍ
#Ò»¸ö×ø±êÖáÉÏ»­ÁËÁ½¸öͼÐÎ
y2 = x**2
plt.figure(num = 5, figsize = (4, 4))
plt.plot(x, y1)
plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
plt.show()

 

Ò»¹²»á»­³öÈýÕÅͼ£¬Ç°Á½ÕźÍÉÏÃæµÄ¼òµ¥°¸Àý»­³öÀ´µÄÁ½ÕÅÒ»Ñù¡£µÚÈýÕÅ£º

3- ÉèÖÃ×ø±êÖá

# -*- coding: utf-8 -*-
"""
ÉèÖÃ×ø±êÖá
"""
import matplotlib.pyplot as plt
import numpy as np
# »æÖÆÆÕͨͼÏñ
x = np.linspace(-1, 1, 50)
y1 = 2 * x + 1
y2 = x**2
plt.figure()
plt.plot(x, y1)
plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
# ÉèÖÃ×ø±êÖáµÄȡֵ·¶Î§
plt.xlim((-1, 1))
plt.ylim((0, 3))
# ÉèÖÃ×ø±êÖáµÄlable
#±êÇ©ÀïÃæ±ØÐëÌí¼Ó×ÖÌå±äÁ¿£ºfontproperties='SimHei',fontsize=14¡£²»È»¿ÉÄÜ»áÂÒÂë
plt.xlabel(u'ÕâÊÇxÖá',fontproperties='SimHei',fontsize=14)
plt.ylabel(u'ÕâÊÇyÖá',fontproperties='SimHei',fontsize=14)
# ÉèÖÃx×ø±êÖá¿Ì¶È, ֮ǰΪ0.25, Ð޸ĺóΪ0.5
#Ò²¾ÍÊÇÔÚ×ø±êÖáÉÏÈ¡5¸öµã£¬xÖáµÄ·¶Î§Îª-1µ½1ËùÒÔÈ¡5¸öµãÖ®ºó¿Ì¶È¾Í±äΪ0.5ÁË
plt.xticks(np.linspace(-1, 1, 5))
plt.show()

ÉÏÃæ´úÂëµÄ»ù´¡ÉϼÓÉÏÏÂÃæ´úÂ루ֱ½Ó¼ÓÔØ×îºóÒ»¾ä´úÂëÇ°Ãæ¼´¿É£©£º

# »ñÈ¡µ±Ç°µÄ×ø±êÖá, gca = get current axis
ax = plt.gca()
# ÉèÖÃÓұ߿òºÍÉϱ߿ò
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# ÉèÖÃx×ø±êÖáΪϱ߿ò
ax.xaxis.set_ticks_position('bottom')
# ÉèÖÃy×ø±êÖáΪ×ó±ß¿ò
ax.yaxis.set_ticks_position('left')
# ÉèÖÃxÖá, yÖÜÔÚ(0, 0)µÄλÖÃ
ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))

Èç¹ûÔÚÉÏÃæ´úÂëµÄ×îºóÒ»¾ä֮ǰ¼ÓÉÏÏÂÃæµÄ´úÂ룺

# ÉèÖÃ×ø±êÖálabelµÄ´óС£¬±³¾°É«µÈÐÅÏ¢
for label in ax.get_xticklabels() + ax.get_yticklabels():
label.set_fontsize(12)
label.set_bbox(dict(facecolor = 'green', edgecolor = 'None', alpha = 0.7))

4- ÉèÖÃlegendͼÀý

# -*- coding: utf-8 -*-
"""
ÉèÖÃ×ø±êÖá
"""
import matplotlib.pyplot as plt
import numpy as np
# »æÖÆÆÕͨͼÏñ
x = np.linspace(-1, 1, 50)
y1 = 2 * x + 1
y2 = x**2
plt.figure()
plt.plot(x, y1)
plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
# ÉèÖÃ×ø±êÖáµÄȡֵ·¶Î§
plt.xlim((-1, 1))
plt.ylim((0, 3))
# ÉèÖÃ×ø±êÖáµÄlable
#±êÇ©ÀïÃæ±ØÐëÌí¼Ó×ÖÌå±äÁ¿£ºfontproperties='SimHei',fontsize=14¡£²»È»¿ÉÄÜ»áÂÒÂë
plt.xlabel(u'ÕâÊÇxÖá',fontproperties='SimHei',fontsize=14)
plt.ylabel(u'ÕâÊÇyÖá',fontproperties='SimHei',fontsize=14)
# ÉèÖÃx×ø±êÖá¿Ì¶È, ֮ǰΪ0.25, Ð޸ĺóΪ0.5
#Ò²¾ÍÊÇÔÚ×ø±êÖáÉÏÈ¡5¸öµã£¬xÖáµÄ·¶Î§Îª-1µ½1ËùÒÔÈ¡5¸öµãÖ®ºó¿Ì¶È¾Í±äΪ0.5ÁË
plt.xticks(np.linspace(-1, 1, 5))
# »ñÈ¡µ±Ç°µÄ×ø±êÖá, gca = get current axis
ax = plt.gca()
# ÉèÖÃÓұ߿òºÍÉϱ߿ò
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# ÉèÖÃx×ø±êÖáΪϱ߿ò
ax.xaxis.set_ticks_position('bottom')
# ÉèÖÃy×ø±êÖáΪ×ó±ß¿ò
ax.yaxis.set_ticks_position('left')
# ÉèÖÃxÖá, yÖÜÔÚ(0, 0)µÄλÖÃ
ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))
plt.show()

5- Ìí¼Ó×¢½âºÍ»æÖƵãÒÔ¼°ÔÚͼÐÎÉÏ»æÖÆÏß»òµã

# -*- coding: utf-8 -*-
"""
Ìí¼Ó×¢½âºÍ»æÖƵãÒÔ¼°ÔÚͼÐÎÉÏ»æÖÆÏß»òµã
"""
import matplotlib.pyplot as plt
import numpy as np
# »æÖÆÆÕͨͼÏñ
x = np.linspace(-3, 3, 50)
y = 2 * x + 1
plt.figure()
plt.plot(x, y)
# ½«ÉÏ¡¢Óұ߿òÈ¥µô
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# ÉèÖÃxÖáµÄλÖü°Êý¾ÝÔÚ×ø±êÖáÉϵÄλÖÃ
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data', 0))
# ÉèÖÃyÖáµÄλÖü°Êý¾ÝÔÚ×ø±êÖáÉϵÄλÖÃ
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data', 0))
# ¶¨Òå(x0, y0)µã
x0 = 1
y0 = 2 * x0 + 1
# »æÖÆ(x0, y0)µã
plt.scatter(x0, y0, s = 50, color = 'blue')
# »æÖÆÐéÏß
plt.plot([x0, x0], [y0, 0], 'k--', lw = 2.5)
# »æÖÆ×¢½âÒ»
plt.annotate(r'$2 * x + 1 = %s$' % y0, xy = (x0, y0), xycoords = 'data', xytext = (+30, -30), \
textcoords = 'offset points', fontsize = 16, arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3, rad = .2'))
# »æÖÆ×¢½â¶þ
plt.text(-3, 3, r'$Test\ text. \mu \sigma_i, \alpha_i$', fontdict = {'size': 16, 'color': 'red'})
plt.show()

6- »æÖÆÉ¢µãͼ

# -*- coding: utf-8 -*-
"""
»æÖÆÉ¢µãͼ
"""
import numpy as np
import matplotlib.pyplot as plt
# Êý¾Ý¸öÊý
n = 1024
# ¾ùֵΪ0, ·½²îΪ1µÄËæ»úÊý
x = np.random.normal(0, 1, n)
y = np.random.normal(0, 1, n)
# ¼ÆËãÑÕɫֵ
color = np.arctan2(y, x)
# »æÖÆÉ¢µãͼ
plt.scatter(x, y, s = 75, c = color, alpha = 0.5)
# ÉèÖÃ×ø±êÖ᷶Χ
plt.xlim((-1.5, 1.5))
plt.ylim((-1.5, 1.5))
# ²»ÏÔÊ¾×ø±êÖáµÄÖµ
plt.xticks(())
plt.yticks(())
plt.show()

7- »æÖÆÖù״ͼ

# -*- coding: utf-8 -*-
"""
»æÖÆÖù״ͼ
"""
import matplotlib.pyplot as plt
import numpy as np
# Êý¾ÝÊýÄ¿
n = 10
x = np.arange(n)
# Éú³ÉÊý¾Ý, ¾ùÔÈ·Ö²¼(0.5, 1.0)Ö®¼ä
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 = 'blue', edgecolor = 'white')
# »æÖÆÖù״ͼ, ÏòÏÂ
plt.bar(x, -y2, facecolor = 'green', edgecolor = 'white')temp = zip(x, y2)
# ÔÚÖù״ͼÉÏÏÔʾ¾ßÌåÊýÖµ, haˮƽ¶ÔÆë, va´¹Ö±¶ÔÆë
for x, y in zip(x, y1):
plt.text(x + 0.05, y + 0.1, '%.2f' % y, ha = 'center', va = 'bottom')
for x, y in temp:
plt.text(x + 0.05, -y - 0.1, '%.2f' % y, ha = 'center', va = 'bottom')
# ÉèÖÃ×ø±êÖ᷶Χ
plt.xlim(-1, n)
plt.ylim(-1.5, 1.5)
# È¥³ý×ø±êÖá
plt.xticks(())
plt.yticks(())
plt.show()

8- »æÖƵǸßÏßͼ

# -*- coding: utf-8 -*-
"""
»æÖƵǸßÏßͼ
"""
import matplotlib.pyplot as plt
import numpy as np
# ¶¨ÒåµÈ¸ßÏ߸߶Ⱥ¯Êý
def f(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(- x ** 2 - y ** 2)
# Êý¾ÝÊýÄ¿
n = 256
# ¶¨Òåx, y
x = np.linspace(-3, 3, n)
y = np.linspace(-3, 3, n)
# Éú³ÉÍø¸ñÊý¾Ý
X, Y = np.meshgrid(x, y)# Ìî³äµÈ¸ßÏßµÄÑÕÉ«, 8ÊǵȸßÏß·ÖΪ¼¸²¿·Ö
plt.contourf(X, Y, f(X, Y), 8, alpha = 0.75, cmap = plt.cm.hot)
# »æÖƵȸßÏß
C = plt.contour(X, Y, f(X, Y), 8, colors = 'black', linewidth = 0.5)
# »æÖƵȸßÏßÊý¾Ý
plt.clabel(C, inline = True, fontsize = 10)
# È¥³ý×ø±êÖá
plt.xticks(())
plt.yticks(())
plt.show()

9- »æÖÆImage

# -*- coding: utf-8 -*-
"""
»æÖÆImage
"""
import matplotlib.pyplot as plt
import numpy as np
# ¶¨ÒåͼÏñÊý¾Ý
a = np.linspace(0, 1, 9).reshape(3, 3)
# ÏÔʾͼÏñÊý¾Ý
plt.imshow(a, interpolation = 'nearest', cmap = 'bone', origin = 'lower')
# Ìí¼ÓÑÕÉ«Ìõ
plt.colorbar()
# È¥µô×ø±êÖá
plt.xticks(())
plt.yticks(())
plt.show()

10- »æÖÆ3DͼÐÎ

# -*- coding: utf-8 -*-
"""
»æÖÆ3dͼÐÎ
"""
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# ¶¨Òåfigure
fig = plt.figure()
# ½«figure±äΪ3d
ax = Axes3D(fig)
# Êý¾ÝÊýÄ¿
n = 256
# ¶¨Òåx, y
x = np.arange(-4, 4, 0.25)
y = np.arange(-4, 4, 0.25)
# Éú³ÉÍø¸ñÊý¾Ý
X, Y = np.meshgrid(x, y)
# ¼ÆËãÿ¸öµã¶ÔµÄ³¤¶È
R = np.sqrt(X ** 2 + Y ** 2)
# ¼ÆËãZÖáµÄ¸ß¶È
Z = np.sin(R)
# »æÖÆ3DÇúÃæ
ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1, cmap = plt.get_cmap('rainbow'))
# »æÖÆ´Ó3DÇúÃæµ½µ×²¿µÄͶӰ
ax.contour(X, Y, Z, zdim = 'z', offset = -2, cmap = 'rainbow')
# ÉèÖÃzÖáµÄά¶È
ax.set_zlim(-2, 2)
plt.show()

11subplot»æÖƶàͼ

# -*- coding: utf-8 -*-
"""
subplot»æÖƶàͼ
"""
import matplotlib.pyplot as plt
plt.figure()
# »æÖƵÚÒ»¸öͼ
plt.subplot(2, 2, 1)
plt.plot([0, 1], [0, 1])
# »æÖƵڶþ¸öͼ
plt.subplot(2, 2, 2)
plt.plot([0, 1], [0, 1])
# »æÖƵÚÈý¸öͼ
plt.subplot(2, 2, 3)
plt.plot([0, 1], [0, 1])
# »æÖƵÚËĸöͼ
plt.subplot(2, 2, 4)
plt.plot([0, 1], [0, 1])
plt.show()

# -*- coding: utf-8 -*-
"""
subplot»æÖƶàͼ
"""
import matplotlib.pyplot as plt
plt.figure()
# »æÖƵÚÒ»¸öͼ
plt.subplot(2, 1, 1)
plt.plot([0, 1], [0, 1])
# »æÖƵڶþ¸öͼ
plt.subplot(2, 3, 4)
plt.plot([0, 1], [0, 1])
# »æÖƵÚÈý¸öͼ
plt.subplot(2, 3, 5)
plt.plot([0, 1], [0, 1])
# »æÖƵÚËĸöͼ
plt.subplot(2, 3, 6)
plt.plot([0, 1], [0, 1])
plt.show()

12- figure»æÖƶàͼ

# -*- coding: utf-8 -*-
"""
figure»æÖƶàͼ
"""
# -*- coding: utf-8 -*-
"""
figure»æÖƶàͼ
"""
import matplotlib.pyplot as plt
# ¶¨Òåfigure
plt.figure()
# figure·Ö³É3ÐÐ3ÁÐ, È¡µÃµÚÒ»¸ö×ÓͼµÄ¾ä±ú, µÚÒ»¸ö×Óͼ¿ç¶ÈΪ1ÐÐ3ÁÐ, ÆðµãÊDZí¸ñ(0, 0)
ax1 = plt.subplot2grid((3, 3), (0, 0), colspan = 3, rowspan = 1)
ax1.plot([0, 1], [0, 1])
ax1.set_title('Test')
# figure·Ö³É3ÐÐ3ÁÐ, È¡µÃµÚ¶þ¸ö×ÓͼµÄ¾ä±ú, µÚ¶þ¸ö×Óͼ¿ç¶ÈΪ1ÐÐ3ÁÐ, ÆðµãÊDZí¸ñ(1, 0)
ax2 = plt.subplot2grid((3, 3), (1, 0), colspan = 2, rowspan = 1)
ax2.plot([0, 1], [0, 1])
# figure·Ö³É3ÐÐ3ÁÐ, È¡µÃµÚÈý¸ö×ÓͼµÄ¾ä±ú, µÚÈý¸ö×Óͼ¿ç¶ÈΪ1ÐÐ1ÁÐ, ÆðµãÊDZí¸ñ(1, 2)
ax3 = plt.subplot2grid((3, 3), (1, 2), colspan = 1, rowspan = 1)
ax3.plot([0, 1], [0, 1])
# figure·Ö³É3ÐÐ3ÁÐ, È¡µÃµÚËĸö×ÓͼµÄ¾ä±ú, µÚËĸö×Óͼ¿ç¶ÈΪ1ÐÐ3ÁÐ, ÆðµãÊDZí¸ñ(2, 0)
ax4 = plt.subplot2grid((3, 3), (2, 0), colspan = 3, rowspan = 1)
ax4.plot([0, 1], [0, 1])
plt.show()

 

»ò

# -*- coding: utf-8 -*-
"""
figure»æÖƶàͼ
"""
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# ¶¨Òåfigure
plt.figure()
# ·Ö¸ôfigure
gs = gridspec.GridSpec(3, 3)
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1, 0:2])
ax3 = plt.subplot(gs[1, 2])
ax4 = plt.subplot(gs[2, :])
# »æÖÆÍ¼Ïñ
ax1.plot([0, 1], [0, 1])
ax1.set_title('Test')
ax2.plot([0, 1], [0, 1])
ax3.plot([0, 1], [0, 1])
ax4.plot([0, 1], [0, 1])
plt.show()

13- figureͼµÄǶÌ×

# -*- coding: utf-8 -*-
"""
figureͼµÄǶÌ×
"""
import matplotlib.pyplot as plt
# ¶¨Òåfigure
fig = plt.figure()
# ¶¨ÒåÊý¾Ý
x = [1, 2, 3, 4, 5, 6, 7]
y = [1, 3, 4, 2, 5, 8, 6]
# figureµÄ°Ù·Ö±È, ´Ófigure 10%µÄλÖÿªÊ¼»æÖÆ, ¿í¸ßÊÇfigureµÄ80%
left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
# »ñµÃ»æÖƵľä±ú
ax1 = fig.add_axes([left, bottom, width, height])
# »æÖƵã(x,y)
ax1.plot(x, y, 'r')
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_title('test')# ǶÌ×·½·¨Ò»
# figureµÄ°Ù·Ö±È, ´Ófigure 10%µÄλÖÿªÊ¼»æÖÆ, ¿í¸ßÊÇfigureµÄ80%
left, bottom, width, height = 0.2, 0.6, 0.25, 0.25
# »ñµÃ»æÖƵľä±ú
ax2 = fig.add_axes([left, bottom, width, height])
# »æÖƵã(x,y)
ax2.plot(x, y, 'r')
ax2.set_xlabel('x')
ax2.set_ylabel('y')
ax2.set_title('part1')# ǶÌ×·½·¨¶þ
plt.axes([bottom, left, width, height])
plt.plot(x, y, 'r')
plt.xlabel('x')
plt.ylabel('y')
plt.title('part2')
plt.show()

14- Ö÷´Î×ø±êÖá

# -*- coding: utf-8 -*-
"""
Ö÷´Î×ø±êÖá
"""
import numpy as np
import matplotlib.pyplot as plt
# ¶¨ÒåÊý¾Ý
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x ** 2
y2 = -1 * y1
# ¶¨Òåfigure
fig, ax1 = plt.subplots()
# µÃµ½ax1µÄ¶Ô³ÆÖáax2
ax2 = ax1.twinx()
# »æÖÆÍ¼Ïñ
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b--')
# ÉèÖÃlabel
ax1.set_xlabel('X data')
ax1.set_xlabel('Y1', color = 'g')
ax2.set_xlabel('Y2', color = 'b')
plt.show()

15- ´´½¨¶¯»­

# -*- coding: utf-8 -*-
"""
¶¯»­
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation# ¶¨Òåfigure
fig, ax = plt.subplots()
# ¶¨ÒåÊý¾Ý
x = np.arange(0, 2 * np.pi, 0.01)
# line, ±íʾֻȡ·µ»ØÖµÖеĵÚÒ»¸öÔªËØ
line, = ax.plot(x, np.sin(x))
# ¶¨Ò嶯»­µÄ¸üÐÂ
def update(i):
line.set_ydata(np.sin(x + i/10))
return line,
# ¶¨Ò嶯»­µÄ³õʼֵ
def init():
line.set_ydata(np.sin(x))
return line,
# ´´½¨¶¯»­
ani = animation.FuncAnimation(fig = fig, func = update, init_func = init, interval = 10, blit = False, frames = 200)
# չʾ¶¯»­
plt.show()
# ¶¯»­±£´æ
#ÎÒÕâÀïÊDZ£´æÎªhtmlÎļþÁË£¬´ò¿ª¼´¿ÉÍêÃÀÔËÐÐ
ani.save('sin.html', writer = 'imagemagick', fps = 30, dpi = 100)

 

ÒÔÉÏËùÓÐÀý×Ó¿ÉÒÔµ½ÎÒµÄgithubÉÏÏÂÔØ£¨³ÖÐø¸üÐÂPythonµÚÈý·½¿âʹÓÃdemoÒÔ¼°³£¼ûpythonÅÀ³æ£¬python΢ÐŵÈÄÚÈÝ£©£º

   
6379 ´Îä¯ÀÀ       27
Ïà¹ØÎÄÕÂ

ÊÖ»úÈí¼þ²âÊÔÓÃÀýÉè¼ÆÊµ¼ù
ÊÖ»ú¿Í»§¶ËUI²âÊÔ·ÖÎö
iPhoneÏûÏ¢ÍÆËÍ»úÖÆÊµÏÖÓë̽ÌÖ
AndroidÊÖ»ú¿ª·¢£¨Ò»£©
Ïà¹ØÎĵµ

Android_UI¹Ù·½Éè¼Æ½Ì³Ì
ÊÖ»ú¿ª·¢Æ½Ì¨½éÉÜ
androidÅÄÕÕ¼°ÉÏ´«¹¦ÄÜ
Android½²ÒåÖÇÄÜÊÖ»ú¿ª·¢
Ïà¹Ø¿Î³Ì

Android¸ß¼¶Òƶ¯Ó¦ÓóÌÐò
Androidϵͳ¿ª·¢
AndroidÓ¦Óÿª·¢
ÊÖ»úÈí¼þ²âÊÔ