实验的题目

1青绿蜷缩浊响
2乌黑蜷缩沉闷
3青绿硬挺清脆
4乌黑稍蜷沉闷
• 可手动或者编程
• 数据自动生成脚本 + 自动数值化脚本：照片，声音

源程序及运行结果

from prettytable import PrettyTable
import matplotlib.pyplot as plt
import matplotlib
import numpy as np

colors=["青绿", "乌黑", "青绿", "乌黑"]
roots=["蜷缩", "蜷缩", "硬挺", "稍蜷"]
voices=["浊响", "沉闷", "清脆", "沉闷"]
isGood=["是","否","否","否"]
x= PrettyTable()
print(x)

#对表格进行数字化处理
colorMap={"青绿":5,"乌黑":10 ,"浅白":15}
rootMap={"蜷缩":10, "蜷缩":20 ,"硬挺":30,"稍蜷":40}
voiceMap={"浊响":20,"沉闷":40,"清脆":60}
isGoodMap={"是":0,"否":70}
print("数字化后的表格为：\n")
digitalTable=PrettyTable()
colorDigital=[]
rootDigital=[]
isGoodDigital=[]
voiceDigital=[]
for c in colors:
colorDigital.append(colorMap[c])
for r in roots:
rootDigital.append(rootMap[r])
for v in voices:
voiceDigital.append(voiceMap[v])
for i in isGood:
isGoodDigital.append(isGoodMap[i])
print(digitalTable)

#对数据进行可视化处理，画出
myfont = matplotlib.font_manager.FontProperties(fname=r'C:/Windows/Fonts/msyh.ttf')

N = 4
menMeans = (20, 35, 30, 35)
womenMeans = (25, 32, 34, 20)
ind = np.arange(N)
width = 0.35

colorBar = plt.bar(ind,colorDigital, width)
rootBar = plt.bar(ind,rootDigital, width, bottom=colorDigital)
voiceBar = plt.bar(ind,voiceDigital, width, bottom=rootDigital)
isGoodBar = plt.bar(ind,isGoodDigital, width, bottom=voiceDigital)

plt.ylabel('各个属性的情况',fontproperties=myfont)
plt.title('不同西瓜样本的可视化图',fontproperties=myfont)
plt.xticks(ind, ('1', '2', '3', '4'))
plt.yticks(np.arange(0, 81, 10))
plt.legend((colorBar[0], rootBar[0],voiceBar[0],isGoodBar[0]), ('color', 'root','voice','isGood'))

plt.show()

+------+------+------+------+
| 色泽 | 根蒂 | 敲声 | 好瓜 |
+------+------+------+------+
| 青绿 | 蜷缩 | 浊响 | 是 |
| 乌黑 | 蜷缩 | 沉闷 | 否 |
| 青绿 | 硬挺 | 清脆 | 否 |
| 乌黑 | 稍蜷 | 沉闷 | 否 |
+------+------+------+------+

+------+------+------+------+
| 色泽 | 根蒂 | 敲声 | 好瓜 |
+------+------+------+------+
| 5 | 20 | 20 | 0 |
| 10 | 20 | 40 | 70 |
| 5 | 30 | 60 | 70 |
| 10 | 40 | 40 | 70 |
+------+------+------+------+

`

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

06-15 867
10-29 562
02-12 2356
02-14 2220
05-29 167
04-04 475
03-12 508
08-29 465
04-25 7815