Reputation: 29
I am working with a (public data set) trying to learn more about how to visualize data and some basics of machine learning, I seem to have got myself really stuck. I'm trying to work with the seaborn violin plot using the hue tag to plot red and white wines by column in the data set vs the quality column...
I'm probably not explaining this well.
anyway my code looks like this:
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()
This gives me an error
AttributeError: 'list' object has no attribute 'fill_betweenx'
I've also tried writing this out to subplot using the example here.
This is a whole other series of errors. I'm at a loss of what to do now... Any help?
Upvotes: 1
Views: 762
Reputation: 5027
The problem is in this part:
sns.violinplot(data=total, x='quality', y=title, hue='color', split=True, ax=[r, c])
please correct the axes assignment this way ax=ax[r, c]:
sns.violinplot(data=total, x='quality', y=title, hue='color', split=True, ax=ax[r, c])
And all should work fine.
Upvotes: 1