赞
踩
- import matplotlib.pyplot as plt
- y1=[10,13,5,40,30,60,70,12,55,25]
- x1=range(0,10)
- x2=range(0,10)
- y2=[5,8,0,30,20,40,50,10,40,15]
- plt.plot(x1,y1,label='Frist line',linewidth=3,color='r',marker='o',
- markerfacecolor='blue',markersize=12)
- plt.plot(x2,y2,label='second line')
- plt.xlabel('Plot Number')
- plt.ylabel('Important var')
- plt.title('Interesting Graph\nCheck it out')
- plt.legend()
- plt.show()
效果展示:
- import matplotlib.pyplot as plt
- y1=[10,13,5,40,30,60,70,12,55,25]
- x1=range(0,20,2)
- x2=range(1,21,2)
- y2=[5,8,0,30,20,40,50,10,40,15]
- plt.bar(x1,y1,label='Frist line')
- #plt.bar(x2,y2,label='second line',color='r')
- plt.xlabel('Plot Number')
- plt.ylabel('Important var')
- plt.title('Interesting Graph\nCheck it out')
- plt.legend()
- plt.show()
效果展示:
- import matplotlib.pyplot as plt
- population_ages = [22,55,62,45,21,22,34,42,42,4,99,102,
- 110,120,121,122,130,111,115,112,80,75,
- 65,54,44,43,42,48]
- x=range(0,130,10)
- plt.hist(population_ages,x,rwidth=0.8,color='r',histtype='stepfilled')
-
- plt.xlabel('Plot Number')
- plt.ylabel('Important var')
- plt.title('Interesting Graph\nCheck it out')
- plt.legend()
- plt.show()
效果展示:
- import matplotlib.pyplot as plt
- population_ages = [22,55,62,45,21,22,34,42,42,4,99,102,
- 110,120,121,122,130,111,115,112,80,75,
- 65,54,44,43,42,48]
- x=range(0,len(population_ages))
- plt.scatter(x,population_ages,label='frist label',s=20)
- help(plt.scatter)
- plt.xlabel('x')
- plt.ylabel('y')
- plt.title('Interesting Graph\nCheck it out')
- plt.legend()
- plt.show()
效果展示:
- import matplotlib.pyplot as plt
- import numpy as np
-
- y = np.array([35, 25, 25, 15])
-
- plt.pie(y,
- labels=['A','B','C','D'], # 设置饼图标签
- colors=["#d5695d", "#5d8ca8", "#65a479", "#a564c9"], # 设置饼图颜色
- explode=(0, 0.2, 0, 0), # 第二部分突出显示,值越大,距离中心越远
- autopct='%.2f%%', # 格式化输出百分比
- )
- plt.title("RUNOOB Pie Test")
- plt.show()
效果展示:
- import numpy as np
- import matplotlib.pyplot as plt
-
- x = np.array([1, 2, 3, 4])
- y = np.array([1, 4, 9, 16])
-
-
- plt.title("RUNOOB grid() Test")
- plt.xlabel("x - label")
- plt.ylabel("y - label")
-
- plt.plot(x, y)
-
- plt.grid(color = 'r', linestyle = '--', linewidth = 0.5)
-
- plt.show()
效果展示:
- import matplotlib.pyplot as plt
- import numpy as np
-
- x = np.array(["Runoob-1", "Runoob-2", "Runoob-3", "C-RUNOOB"])
- y = np.array([12, 22, 6, 18])
-
- plt.bar(x,y)
- plt.show()
效果展示:
- import matplotlib.pyplot as plt
- import numpy as np
-
- #plot 1:
- x = np.array([0, 6])
- y = np.array([0, 100])
-
- plt.subplot(2, 2, 1)
- plt.plot(x,y)
- plt.title("plot 1")
-
- #plot 2:
- x = np.array([1, 2, 3, 4])
- y = np.array([1, 4, 9, 16])
-
- plt.subplot(2, 2, 2)
- plt.plot(x,y)
- plt.title("plot 2")
-
- #plot 3:
- x = np.array([1, 2, 3, 4])
- y = np.array([3, 5, 7, 9])
-
- plt.subplot(2, 2, 3)
- plt.plot(x,y)
- plt.title("plot 3")
-
- #plot 4:
- x = np.array([1, 2, 3, 4])
- y = np.array([4, 5, 6, 7])
-
- plt.subplot(2, 2, 4)
- plt.plot(x,y)
- plt.title("plot 4")
-
- plt.suptitle("RUNOOB subplot Test")
- plt.show()
效果展示:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。