Me gustaría dibujar la distribución de dos variables. Pensé que podría hacer gráficos de caja en los ejes de abscisas y ordenadas, o una función de distribución. Me gustaría algo como:
O:
Hasta hoy tengo:
def plot_mean(columns_x, columns_y):
try:
plt.axis([-1, 1, -1, 1])
plt.grid(True)
plt.xlabel(columns_x)
plt.ylabel(columns_y)
# We get all parties from df_parties_means
for party in df_parties_means['Party']:
# we get the probability distribution function
party_x = df_parties_means.loc[
((df_parties_means['Question'] == columns_x) & (df_parties_means['Party'] == party)), 'Mean']
party_y = df_parties_means.loc[
((df_parties_means['Question'] == columns_y) & (df_parties_means['Party'] == party)), 'Mean']
# we plot the party related to the questions
plt.scatter(party_x.values[0], party_y.values[0],
alpha=0.4, edgecolors='w',label = party)
plt.text(party_x.values[0], party_y.values[0], party, fontsize=10)
# We plot the people preferences
plt.scatter(df_features[columns_x].mean( skipna = True), df_features[columns_y].mean( skipna = True),
alpha=0.4, edgecolors='w')
f, ax = plt.subplots(figsize=(6, 6))
# plot the density function for the people preferences
sns.kdeplot(df_features[columns_x], df_features[columns_y], ax=ax)
sns.rugplot(df_features[columns_x], color="g", ax=ax)
sns.rugplot(df_features[columns_y], vertical=True, ax=ax);
plt.title('Perceptual map',y=1.05)
plt.show()
except Exception as e:
print(len(party_x))
print(len(party_y))
print("columns_x: ", columns_x)
print("columns_y: ", columns_y)
import itertools
pairs = list(itertools.combinations(df_features.columns, 2))
[plot_mean(pair[0],pair[1]) for pair in pairs]
Pero me dibuja: