Python中实现图形绘制的基本操作是什么
Admin 2022-06-24 群英技术资讯 710 次浏览
第一个图形从简单的开始。
# importing the required module import matplotlib.pyplot as plt # x axis values x = [1,2,3] # corresponding y axis values y = [2,4,1] # plotting the points plt.plot(x, y) # naming the x axis plt.xlabel('x - axis') # naming the y axis plt.ylabel('y - axis') # giving a title to my graph plt.title('My first graph!') # function to show the plot plt.show()
如果想在同一张图上再绘制多条线,可反复使用.plot()
函数。
import matplotlib.pyplot as plt # line 1 points x1 = [1,2,3] y1 = [2,4,1] # plotting the line 1 points plt.plot(x1, y1, label = "line 1") # line 2 points x2 = [1,2,3] y2 = [4,1,3] # plotting the line 2 points plt.plot(x2, y2, label = "line 2") # naming the x axis plt.xlabel('x - axis') # naming the y axis plt.ylabel('y - axis') # giving a title to my graph plt.title('Two lines on same graph!') # show a legend on the plot plt.legend() # function to show the plot plt.show()
下面将讨论适用于几乎所有场景的一些基本自定义。
import matplotlib.pyplot as plt # x axis values x = [1,2,3,4,5,6] # corresponding y axis values y = [2,4,1,5,2,6] # plotting the points plt.plot(x, y, color='green', linestyle='dashed', linewidth = 3,marker='o', markerfacecolor='blue', markersize=12) # setting x and y axis range plt.ylim(1,8) plt.xlim(1,8) # naming the x axis plt.xlabel('x - axis') # naming the y axis plt.ylabel('y - axis') # giving a title to my graph plt.title('Some cool customizations!') # function to show the plot plt.show()
如上面代码所示,我们进行了一些自定义的改变:
pyplot
模块使用自动缩放功能来设置轴范围和比例。免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
装饰器经常被用于有切面需求的场景,较为经典的有插入日志、性能测试、事务处理等。装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷同代码并继续重用。装饰器的作用就是为已经存在的对象添加额外的功能。
Python中有三个去除头尾字符、空白符的函数,它们依次为:strip: 用来去除头尾字符、空白符(包括 n、 r、 t、& 39; & 39;,即:换行、回
本文详细讲解了Python集成开发环境Pycharm的使用及技巧,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
tansforms功能类似于在计算机视觉流程里的图像预处理部分的数据增强,接下来通过代码介绍下Pytorch使用transforms的详细过程,感兴趣的朋友一起看看吧
内容介绍写在前面创建一个文档先实现第一步,写入一个标题添加文字段落列表的添加图片的添加表格添加相关样式设置页眉和页脚写在前面python-docx不支持doc文档,一定要注意该点,如果使用do
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008