python图形集合设计
#-- codeing = utf-8 --
#@Time:2020/12/29 15:25
#@Author:publishment ghost
#@File:varity of picture toos.py
#@Software:PyCharm
from scipy import stats
from matplotlib import pyplot
import matplotlib.pyplot as plt
from math import pi,sin,cos
import numpy as np
import matplotlib.mlab as mlab
import seaborn as sns
import numpy as np
import scipy
print("-"*10+“小李数据图形处理系统”+"-"*10)
print(" 1-----折线图\n",
“2-----柱形图\n”,
“3-----数据拟态分析(1.散点图 )\n”,
“4-----曲线图\n”,
“5-----扇形图\n”,
“6-----离散图形\n”
)
曲线粗细变换
def
varity = int(input(“请输入你想要的图形样式:”))
#折线图
if varity == 1:
temp_date = int(input(“输入你的数据组数:”))
if temp_date == 1:
picture_xlist1 = []
picture_ylist1 = []
picture_max = []
data_number_1 = int(input(“请输入你的数据总数”))
for i in range(1,data_number_1 + 1):
num_1 = eval(input(“输入的横轴的数据:”))
num_2 = eval(input(“输入你纵轴的数据:”))
picture_xlist1.append(num_1)
picture_ylist1.append(num_2)
picture_max.append(picture_xlist1)
picture_max.append(picture_ylist1)
print(“确认你的数据做坐标是否正确” + str(picture_max))
#错误检查递归
x_mark_1 = str(input(“请输入你的x轴名称:”))
pyplot.xlabel(x_mark_1)
y_mark_1 = str(input(“请输入你的y轴名称:”))
pyplot.ylabel(y_mark_1)
pyplot.plot(picture_xlist1,picture_ylist1)
pyplot.show()
elif temp_date == 2:
picture_xlist1 = []
picture_ylist1 = []
picture_xlist2 = []
picture_ylist2 = []
‘’’
picture_xmid = []#平均值
mid_1 = np.sum([picture_xlist1,picture_xlist2],axis = 0)
mid_2 = np.sum([picture_ylist1,picture_ylist2],axis = 0)
mid_1 = mid_1 / 2
mid_2 = mid_2 / 2
mid_1 = list(mid_1)
mid_2 = list(mid_2)
#picture_xmid = (picture_xlist1 + picture_xlist2)/2
#picture_ymid = (picture_ylist1 + picture_ylist2)/2
‘’’
data_number_2 = int(input(“请输入你的数据总数”))
for i in range(1,data_number_2 + 1):
num_1 = eval(input(“输入你第一组的横轴的数据:”))
num_2 = eval(input(“输入你第一组的纵轴的数据:”))
num_3 = eval(input(“输入你第二组的横轴的数据:”))
num_4 = eval(input(“输入你第二组的纵轴的数据:”))
picture_xlist1.append(num_1)
picture_ylist1.append(num_2)
picture_xlist2.append(num_3)
picture_ylist2.append(num_4)
#平均值
print(“确认你的第一组x轴数据是否正确” + str(picture_xlist1))
print(“确认你的第一组y轴数据是否正确” + str(picture_ylist1))
print(“确认你的第二组x轴数据是否正确” + str(picture_xlist2))
print(“确认你的第二组y轴数据是否正确” + str(picture_ylist2))
#print(“确认你x轴的前两组的平均值队列为”+ str(mid_1))
#print(“确认你y轴的前两组的平均值队列为”+ str(mid_2))
#错误检查递归
x_mark_1 = str(input(“请输入你的x轴名称:”))
pyplot.xlabel(x_mark_1)
y_mark_1 = str(input(“请输入你的y轴名称:”))
pyplot.ylabel(y_mark_1)
pyplot.plot(picture_xlist1,picture_ylist1)
pyplot.plot(picture_xlist2,picture_ylist2)
#pyplot.plot(mid_1,mid_2)
pyplot.show()
#柱形图
elif varity == 2:
temp_date1 = int(input(“输入你的数据组数:”))
if temp_date1 == 1:
picture_xlist1 = []
picture_ylist1 = []
data_number_1 = int(input(“请输入你的数据总数”))
for i in range(1,data_number_1 + 1):
num_1 = eval(input(“输入你第一组的横轴的数据:”))
num_2 = eval(input(“输入你纵轴的数据:”))
picture_xlist1.append(num_1)
picture_ylist1.append(num_2)
print(“确认你的x轴数据是否正确” + str(picture_xlist1))
print(“确认你的y轴数据是否正确” + str(picture_ylist1))
#错误检查递归
x_mark_1 = str(input(“请输入你的x轴名称:”))
pyplot.xlabel(x_mark_1)
y_mark_1 = str(input(“请输入你的y轴名称:”))
pyplot.ylabel(y_mark_1)
pyplot.bar(picture_xlist1,picture_ylist1)
pyplot.show()
elif temp_date1 == 2:
picture_xlist1 = []
picture_ylist1 = []
picture_xlist2 = []
picture_ylist2 = []
data_number_2 = int(input(“请输入你的数据总数”))
for i in range(1,data_number_2 + 1):
num_1 = eval(input(“输入你第一组的横轴的数据:”))
num_2 = eval(input(“输入你第一组的纵轴的数据:”))
num_3 = eval(input(“输入你第二组的横轴的数据:”))
num_4 = eval(input(“输入你第二组的纵轴的数据:”))
picture_xlist1.append(num_1)
picture_ylist1.append(num_2)
picture_xlist2.append(num_3)
picture_ylist2.append(num_4)
print(“确认你的第一组x轴数据是否正确” + str(picture_xlist1))
print(“确认你的第一组y轴数据是否正确” + str(picture_ylist1))
print(“确认你的第二组x轴数据是否正确” + str(picture_xlist2))
print(“确认你的第二组y轴数据是否正确” + str(picture_ylist2))
#错误检查递归
x_mark_1 = str(input(“请输入你的x轴名称:”))
pyplot.xlabel(x_mark_1)
y_mark_1 = str(input(“请输入你的y轴名称:”))
pyplot.ylabel(y_mark_1)
pyplot.bar(picture_xlist1,picture_ylist1)
pyplot.bar(picture_xlist2,picture_ylist2)
pyplot.show()
#数据拟态图(散点图,离散图)
elif varity == 3:
date_ccu1 = int(input(“请选择你要做的图像类型:”))
#散点图
if date_ccu1 ==1:
temp_date1 = int(input(“输入你的数据组数:”))
if temp_date1 == 1:
picture_xlist1 = []
picture_ylist1 = []
data_number_1 = int(input(“请输入你的数据总数”))
for i in range(1,data_number_1 + 1):
num_1 = eval(input(“输入你第一组的横轴的数据:”))
num_2 = eval(input(“输入你纵轴的数据:”))
picture_xlist1.append(num_1)
picture_ylist1.append(num_2)
print(“确认你的x轴数据是否正确” + str(picture_xlist1))
print(“确认你的y轴数据是否正确” + str(picture_ylist1))
#错误检查递归
x_mark_1 = str(input(“请输入你的x轴名称:”))
pyplot.xlabel(x_mark_1)
y_mark_1 = str(input(“请输入你的y轴名称:”))
pyplot.ylabel(y_mark_1)
pyplot.scatter(picture_xlist1,picture_ylist1)
pyplot.show()
elif temp_date1 == 2:
picture_xlist1 = []
picture_ylist1 = []
picture_xlist2 = []
picture_ylist2 = []
data_number_2 = int(input(“请输入你的数据总数”))
for i in range(1,data_number_2 + 1):
num_1 = eval(input(“输入你第一组的横轴的数据:”))
num_2 = eval(input(“输入你第一组的纵轴的数据:”))
num_3 = eval(input(“输入你第二组的横轴的数据:”))
num_4 = eval(input(“输入你第二组的纵轴的数据:”))
picture_xlist1.append(num_1)
picture_ylist1.append(num_2)
picture_xlist2.append(num_3)
picture_ylist2.append(num_4)
print(“确认你的第一组x轴数据是否正确” + str(picture_xlist1))
print(“确认你的第一组y轴数据是否正确” + str(picture_ylist1))
print(“确认你的第二组x轴数据是否正确” + str(picture_xlist2))
print(“确认你的第二组y轴数据是否正确” + str(picture_ylist2))
#错误检查递归
x_mark_1 = str(input(“请输入你的x轴名称:”))
pyplot.xlabel(x_mark_1)
y_mark_1 = str(input(“请输入你的y轴名称:”))
pyplot.ylabel(y_mark_1)
pyplot.scatter(picture_xlist1,picture_ylist1)
pyplot.scatter(picture_xlist2,picture_ylist2)
pyplot.show()
#离散图
elif date_ccu1 == 2:
sns.set(style=“ticks”)
df = sns.load_dataset(“anscombe”)
sns.lmplot(x = “x”, y = “y”, col = “dataset”, hue = “dataset”, data = df,
col_wrap = 2, ci = None, palette = “muted”, height = 4,
scatter_kws={“s”: 50, “alpha”: 1});
#扇形图
elif varity == 5:
#每个扇形元素名称
labels = []
picture_ylist1 = []
data_number_1 = int(input(“请输入你要建立扇形图总数”))
for i in range(1,data_number_1 + 1):
num_1 = str(input(“输入你扇形图每个区域的名称:”))
num_2 = int(input(“输入每个部分的占比:”))
labels.append(num_1)
picture_ylist1.append(num_2)
print(“确认你扇形图名称是否正确” + str(labels))
print(“确认你的每个元素占比是否正确” + str(picture_ylist1))
#错误检查递归
fig = plt.figure()
plt.pie(picture_ylist1,labels = labels,autopct = ‘%1.2f%%’)
name_7 =str(input(“请输入你的图像名称:”))
plt.title(name_7)
plt.show()
#线性回归函数
elif varity == 6:
number_x1 = []
number_y1 = []
number_x2 = []
number_y2 = []
term = int(input(“请输入你的数据组数:”))
for i in range(1,term+1):
quxian_x = input(“请输入你曲线的x轴数据:”)
number_x1.append(float(quxian_x))
quxian_y = input(“请输入你曲线的y轴数据:”)
number_y1.append(float(quxian_y))
‘’’
sandian_x = input(“请输入你散点的x轴数据:”)
number_x2.append(sandian_x)
sandian_y = input(“请输入你散点的y轴数据:”)
number_y2.append(sandian_y)
‘’’
#函数scipy.stats.linregress计算线性相关的系数及回归曲线
#number_x1 = np.array(number_x1)#将列表转为数组
#number_y1 = np.array(number_y1)
r = scipy.stats.linregress(number_x1,number_y1)
number_x1 = np.array(number_x1)
number_y1 = np.array(number_y1)
slope = r[0]
inter = r[1]
correct = r[3]
pyplot.scatter(number_x1,number_y1)#建立散点
#quxian_x = np.array(quxian_x)
#quxian_y = np.array(quxian_y)
x1 = min(quxian_y)
#x1 = np.array(x1)
y1 = inter+slopex1
#y1 = np.array(y1)
x2 = max(quxian_y)
#x2 = np.array(x2)
y2 = inter+slopex2
#y2 = np.array(y2)
pyplot.plot([x1,x2],[y1,y2])
pyplot.show()
#还在修改完善