python 从文件导入数据画图
2017-08-04 09:41
330 查看
今天早晨花了三个小时解决了一个bug,症结在于忽略了turtle库中colormode的限制。在这里做一个复盘,希望其他初学者能够避免这个错误。
""" Created on Fri Aug 4 06:27:45 2017 @author: suqi791776 """ import turtle #inport Turtle def main(): # firstly setup the window turtle.title("plot the graph according file data") turtle.setup(800, 600, 0, 0) # secondly setup the parameters of pen p = turtle.Turtle() p.color = ("red") p.pensize(5) p.speed(2) #thirly read the file result = [] infile = open("data.txt","r") for line in infile: result.append(list(map(float,line.split(',')))) #put datas #in a list; list(map(function,list)) is correct usage, not #map(function,list) print(result) #plot the graph for i in range(len(result)): p.pencolor((result[i][3],result[i][4],result[i][5])) #if turtle.colormode(1), the parameter in #p.pencolor((r,g,b)) must between 0 and 1. p.forward(result[i][0]) if result[i][1]: p.left(result[i][2]) else: p.right(result[i][2]) p.goto(0,0) #return the original point main()
相关文章推荐
- python用read_csv导入txt文件时的数据丢失问题
- mysql 通过Python导入clickhouse 行数对于完成速度的影响(数据文件无压缩)
- [Python]将Excel文件中的数据导入MySQL
- python从Microsoft Excel文件中导入数据
- [Python]将Excel文件中数据导入MySQL
- Python绘制直方图(Histograms)—从文件中读取数据画图update@2017-05-17
- SQLite3创建数据库的方法 和 SQLite从Excel文件中导入数据 及 python/qpython sqlite 中文 乱码
- python读取文件数据导入到hbase
- 外部表和文件导入数据
- json文件 数据导入excel----->(jxl)
- 大数据文件导入MySql处理方式
- 将excel文件中的商品数据导入到数据库,并实现相关检索以及模糊搜索功能
- Ubuntu下python应如何将.py文件当模块进行导入
- 【R和Python对比】数据导入和初步整理
- 使用Python Requests上传表单数据和文件
- python引入导入自定义模块和外部文件
- 【SQL Server数据迁移】把csv文件中的数据导入SQL Server的方法
- android 把数据导入到excel文件中的三种方法
- dmp数据文件导入问题
- Python数据可视化-Matplotlib学习笔记(2)--画图进阶