![a6278c08f05c83043229dc3707c9eadb.png](https://i-blog.csdnimg.cn/blog_migrate/711373cfaf7c3a6692706f5ce8529b86.png)
# 1.列表生成:通俗理解就是使用for循环快速创建一个列表my_list = []for i in range(1,6): my_list.append(i)print(my_list)# 1.1列表生成式创建列表my_list = [value *2 for value in range(1,6)]print(my_list)# 1.2结合系统的函数去使用my_list = [len(value) for value in ['abc','bcd']]print(my_list)my_list = [value+'123' for value in ['abc','bcd']]print(my_list[0])# 1.3结合if语句来使用# 1- 10 的偶数给我装入到列表当中my_list = [value for value in range(1,11) if value%2 ==0]print(my_list)# 1.4双层for 循环# for x in range(1,3):# print(x)# for y in range(1,3):# print(y) my_list = [[x,y]for x in range(1,3) for y in range(1,3)]print(my_list)
![125a61530e1cd20ce5f60bffb278f2ab.png](https://i-blog.csdnimg.cn/blog_migrate/a5231793dc44f3de2df9ebf222a08166.png)
![102409d9daf969557c1ca3fd11b0e914.png](https://i-blog.csdnimg.cn/blog_migrate/0bd03a5e699754499718ca34092ad035.png)
![8faa8434ff071010902dc65580ab74de.png](https://i-blog.csdnimg.cn/blog_migrate/16c442c2d20fe695ca4347baaf359ae4.png)
import matplotlib.pyplot as plt # 在jupyter中执行的时候显示图片%matplotlib inline#传入x值和y值进行绘制plt.plot([1,0,9],[4,5,6])#展示这个图形plt.show()
![dce26ee99a1b6e910e9f7af8a0676dc5.png](https://i-blog.csdnimg.cn/blog_migrate/7a95ab95f7efc3e011500a9559cd7c23.png)
![6cfec3ff9ee34fcbd3ea7907ae66c42c.png](https://i-blog.csdnimg.cn/blog_migrate/4d5a1f297671194a507ada8cdc1faadb.png)
from matplotlib import pyplot as pltx = range(1,8) # x轴的位置y = [17, 17, 18, 15, 11, 11,17]# 传入x和y, 通过plot画折线图plt.plot(x,y) plt.show()from matplotlib import pyplot as pltx = range(1,8) # x轴的位置y = [17, 17, 18, 15, 11, 11, 13]# 传入x和y, 通过plot画折线图#alpha 毛玻璃效果 透明度plt.plot(x, y, color='red',alpha=0.1,linestyle='--',linewidth=10) plt.show()'''基础属性设置color='red' : 折线的颜色alpha=0.5 : 折线的透明度(0-1)linestyle='--' : 折线的样式linewidth=3 : 折线的宽度''''''线的样式- 实线(solid)-- 短线(dashed)-. 短点相间线(dashdot): 虚点线(dotted)'''from matplotlib import pyplot as pltx = range(1,8) # x轴的位置y = [17, 17, 18, 15, 11, 11, 13]# 传入x和y, 通过plot画折线图plt.plot(x, y, marker='o') plt.show()
![8355f82346cd149a31f218729e338b80.png](https://i-blog.csdnimg.cn/blog_migrate/8b3b5335b2ea72db6a379babb8f598fc.png)
![9b61e4e87c80e893224d9af608520c9d.png](https://i-blog.csdnimg.cn/blog_migrate/a6cbf47cfdc33e84af0f581030351ca9.png)
![fbe6c5de01f82b6366638cff50555984.png](https://i-blog.csdnimg.cn/blog_migrate/73960263e3609ed6f4eac42a445c030d.png)
from matplotlib import pyplot as pltimport randomx = range(2,26,2) # x轴的位置y = [random.randint(15, 30) for i in x]# 设置图片的大小'''figsize:指定figure的宽和高,单位为英寸;dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 1英寸等于2.5cm,A4纸是 21*30cm的纸张 '''# 根据画布对象plt.figure(figsize=(20,8),dpi=80)plt.plot(x,y) # 传入x和y, 通过plot画图#plt.show()#坑# 保存(注意: 要放在绘制的下面,并且plt.show()会释放figure资源,如果在显示图像之后保存图片将只能保存空图片。)plt.savefig(&#