我正在和一个(public data set)一起工作,试图学习更多关于如何可视化数据和一些机器学习的基础知识,我似乎真的把自己卡住了。我正在尝试使用seaborn小提琴绘图,使用色调标签在数据集中按列绘制红葡萄酒和白葡萄酒,而不是按质量列绘制。。。在
我可能没有解释清楚。在
总之,我的代码是这样的:
class Wine():
def __init__(self):
self.Process()
def Process(self):
whit = pds.read_csv("winequality-white.csv", sep=";", header=0)
reds = pds.read_csv("winequality-red.csv", sep=";", header=0)
self.Plot_Against_Color(whit, reds)
def Plot_Against_Color(self, white, red):
nwhites = white.shape[0]; nreds = red.shape[0]
white_c = ["white"] * nwhites; red_c = ["red"] * nreds
white['color'] = white_c; red['color'] = red_c
total = white.append(red, ignore_index=True)
parameters = list(total)
nparameters = len(parameters)
plt_rows = math.floor((nparameters - 1) / 3)
if (nparameters - 1) % 3 > 0:
plt_rows += 1
fig, ax = plt.subplots(int(plt_rows), 3)
fig.suptitle('Characteristics of Red and White Wine as a Function of Quality')
for i in range(len(parameters)):
title = parameters[i]
if title == 'quality' or title == 'color':
continue
print(title)
r = math.floor(i / 3);
c = i % 3
sns.violinplot(data=total, x='quality', y=title, hue='color', split=True, ax=[r, c])
ax[r, c].set_xlabel('quality')
ax[r, c].set_ylabel(title)
plt.tight_layout()
这给了我一个错误
^{pr2}$我还尝试过使用示例here将其写入子批处理。在
这是另一系列错误。我现在不知道该怎么办。。。有什么帮助吗?在
问题在于这一部分:
请按以下方式更正轴分配:ax=ax[r,c]:
^{pr2}$一切都会好起来的。在
相关问题 更多 >
编程相关推荐