Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions m5/1028m5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import matplotlib.pyplot as plt
import numpy as np
import csv
import pandas as pd


c_list = ["red", "green", "blue"] * 5
h_list = ["ax/mg", "ay/mg", "az/mg", "gx_deg/s", "gy_deg/s", "gz_deg/s", "mx/mG", "my/mG", "mz/mG", "Yaw", "Pitch", "Roll", "rate/Hz"]
# dic = dict(zip(h_list, c_list))
for i in range(13):
d_list = []

with open('C:/Users/F1336489/Desktop/m5_data.csv', 'r') as csvfile:
# 创建一个阅读器:将f传给csv.reader
reader = csv.reader(csvfile)
# 使用csv的next函数,将reader传给next,将返回文件的下一行
header_row = next(reader)

# for index, column_header in enumerate(header_row):
# print(index, column_header)


data = []
# 遍历reader的余下的所有行(next读取了第一行,reader每次读取后将返回下一行)
for row in reader:
# 将字符串转换成数字
high = float(row[i])
data.append(high)
#print(data)

# 绘制图形
fig = plt.figure(dpi=128, figsize=(10, 6))
# plt.subplot(431)
plt.plot(data, c=str(c_list[i]))
# 设置图形的格式
plt.title(str(h_list[i]), fontsize=24)
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.tick_params(axis='both', which="major", labelsize=16)

plt.show()
26 changes: 26 additions & 0 deletions m5/1029data3D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import matplotlib.pyplot as plt
import numpy as np
import csv
import pandas as pd
import pymysql
from mpl_toolkits.mplot3d import Axes3D

db = pymysql.connect(host="localhost", user="root",
password="16888", db="csv_db", port=3306)

df = pd.read_sql_query("select * from m5db;", db)
yaw = pd.DataFrame(df, columns=['Yaw'])
pitch = pd.DataFrame(df, columns=['Pitch'])
roll = pd.DataFrame(df, columns=['Roll'])

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(yaw, pitch, roll)
ax.set_xlabel('pitch')
ax.set_ylabel('yaw')
ax.set_zlabel('roll')
ax.view_init(elev=10, azim=235)
plt.show()
2 changes: 2 additions & 0 deletions m5/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
66 changes: 66 additions & 0 deletions m5/csv2db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-


import pymysql
import pandas as pd

# 参数设置,建立连接
db = pymysql.connect(host="localhost", user="root",
password="16888", db="localsql", port=3306)

# 自动确认commit True
db.autocommit(1)
# 设置光标
cursor = db.cursor()

df = pd.read_csv('qe.csv', encoding='utf-8')


# 一个根据pandas自动识别type来设定table的type
def make_table_sql(df):
columns = df.columns.tolist()
types = df.ftypes
# 添加id 制动递增主键模式
make_table = []
char = ''
for item in columns:
if 'int' in types[item]:
char = item + ' INT'
elif 'float' in types[item]:
char = item + ' FLOAT'
elif 'object' in types[item]:
char = item + ' VARCHAR(255)'
elif 'datetime' in types[item]:
char = item + ' DATETIME'
make_table.append(char)
return ','.join(make_table)


# csv 格式输入 mysql 中
def csv2mysql(db_name, table_name, df):
# 创建database
cursor.execute('CREATE DATABASE IF NOT EXISTS {}'.format(db_name))
# 选择连接database

db.select_db(db_name)

# 创建table
cursor.execute('DROP TABLE IF EXISTS {}'.format(table_name))
cursor.execute('CREATE TABLE {}({})'.format(table_name, make_table_sql(df)))

values = df.values.tolist()
# 根据columns个数
s = ','.join(['%s' for _ in range(len(df.columns))])
# executemany批量操作 插入数据 批量操作比逐个操作速度快很多
cursor.executemany('INSERT INTO {} VALUES ({})'.format(table_name, s), values)


csv2mysql('csv_db', 'm5db', df)
# 光标关闭
cursor.close()
# 连接关闭
db.close()



13 changes: 13 additions & 0 deletions m5/mat1028.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1, 1, 50)
y = 2*x + 1

plt.figure()
plt.plot(x, y)
plt.show()

Loading