matplot 绘图
matplot 绘图#!/usr/bin/python# -*- coding:utf-8 -*-from matplotlib importpyplot as pltimport matplotlibimport randomdef mymatplotlib():x=range(2,26,2)print(list(x))y=[15,13,14....
·
matplot 绘图
#!/usr/bin/python
# -*- coding:utf-8 -*-
from matplotlib import pyplot as plt
import matplotlib
import random
def mymatplotlib():
x=range(2,26,2)
print(list(x))
y=[15,13,14.5,17,20,25,26,26,27,22,18,15]
plt.plot(x,y)
plt.show()
def mymatplotlib2():
plt.figure(figsize=(20,8),dpi=80)
x=range(2,26,2)
print(list(x))
y=[15,13,14.5,17,20,25,26,26,27,22,18,15]
plt.plot(x,y)
plt.savefig("./pic1.png")
plt.show()
def mymatplotlib3():
plt.figure(figsize=(20,8),dpi=80)
x=range(2,26,2)
print(list(x))
y=[15,13,14.5,17,20,25,26,26,27,22,18,15]
plt.plot(x,y)
plt.xticks(x)
plt.savefig("./pic2.png")
plt.show()
def mymatplotlib4():
# print(matplotlib.matplotlib_fname())
x=range(120)
y=[random.randint(20,35) for i in range(120)]
print(len(x))
print(len(y))
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
x_=x[::5]
x_tick=["10点{}分".format(i) for i in range(60)]
x_tick+=["11点{}分".format(i) for i in range(60)]
plt.xticks(x_,x_tick[::5],rotation=45)
plt.yticks(range(min(y),max(y)+1))
plt.xlabel("时间")
plt.ylabel("温度")
plt.title("10点到12点的每分钟的温度变化")
plt.show()
pass
def mymatplotlib5():
x=range(11,31)
y = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
print(len(x))
print(len(y))
plt.plot(x,y)
x_tick=["{}岁".format(i) for i in range(11,31)]
plt.xticks(x,x_tick,rotation=45)
plt.yticks(range(min(y),max(y)+1))
plt.xlabel("年龄")
plt.ylabel("异性朋友个数")
plt.title("随年龄增长每年结交异性朋友的个数")
plt.show()
pass
def mymatplotlib6():
x=range(11,31)
y = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
y_2 = [1, 0, 3, 1, 2, 2, 3, 3, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]
print(len(x))
print(len(y))
plt.plot(x,y,label="自己")
plt.plot(x, y_2,label="同桌",linestyle="--",color="g")
x_tick=["{}岁".format(i) for i in range(11,31)]
plt.xticks(x,x_tick,rotation=45)
plt.yticks(range(min(y),max(y)+1))
plt.xlabel("年龄")
plt.ylabel("异性朋友个数")
plt.title("随年龄增长每年结交异性朋友的个数")
plt.legend(loc="upper left")
plt.grid(alpha=0.4,linestyle=":")
plt.show()
pass
if __name__ == '__main__':
print("hello")
# mymatplotlib()
print("=================")
# mymatplotlib2()
print("=================")
# mymatplotlib3()
print("=================")
# mymatplotlib4()
print("=================")
# mymatplotlib5()
print("==================")
mymatplotlib6()
更多推荐
已为社区贡献17条内容
所有评论(0)