Wie zeichnet man nur das untere Dreieck einer seegeborenen Heatmap auf?Python

Python-Programme
Anonymous
 Wie zeichnet man nur das untere Dreieck einer seegeborenen Heatmap auf?

Post by Anonymous »

Ich habe eine Liste mit Listen aller_Genres, wobei jede Unterliste Genres für eine bestimmte Fernsehsendung enthält und jede andere Unterliste sich auf verschiedene Fernsehsendungen bezieht. Ich möchte eine Seaborn-Heatmap zeichnen, jedoch nur mit dem unteren Dreiecksteil. Folgendes habe ich bisher versucht:

Code: Select all

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(rc={'figure.figsize':(16,9)})

all_genres = [['Drama', 'History'], ['Documentary'], ['Action', 'Drama', 'History'], ['Documentary'], ['Crime', 'Drama', 'Thriller'], ['Action', 'Adventure', 'Drama'], ['Crime', 'Drama', 'Thriller'], ['Documentary'], ['Documentary'], ['Documentary'], ['Animation', 'Adventure', 'Comedy'], ['Crime', 'Drama'], ['Documentary', 'History', 'War'], ['Animation', 'Action', 'Adventure'], ['Documentary'], ['Documentary', 'Music'], ['Crime', 'Drama', 'Mystery'], ['Documentary', 'History', 'War'], ['Fantasy', 'Horror', 'Mystery'], ['Documentary'], ['Drama'], ['Animation', 'Action', 'Adventure'], ['Adventure', 'Drama', 'Sci-Fi'], ['Documentary', 'History', 'War'], ['Biography', 'Drama', 'History'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Drama', 'Thriller'], ['Animation', 'Action', 'Adventure'], ['Animation', 'Crime', 'Drama'], ['Comedy', 'News', 'Talk-Show'], ['Documentary'], ['Animation', 'Action', 'Adventure'], ['Drama', 'Sci-Fi', 'Thriller'], ['Documentary'], ['Animation', 'Action', 'Adventure'], ['Comedy'], ['Comedy', 'Romance'], ['Drama', 'Romance'], ['Documentary'], ['Comedy'], ['Drama', 'Thriller', 'War'], ['Comedy'], ['Documentary', 'History', 'War'], ['Drama', 'Fantasy', 'Horror'], ['Animation', 'Adventure', 'Comedy'], ['Crime', 'Drama', 'Fantasy'], ['Comedy'], ['Animation', 'Adventure', 'Drama'], ['Comedy', 'Drama'], ['Comedy', 'Drama'], ['Biography', 'Crime', 'Drama'], ['Comedy', 'Drama'], ['Biography', 'Drama', 'History'], ['Comedy'], ['Drama'], ['Crime', 'Drama'], ['Comedy', 'War'], ['Drama', 'Mystery', 'Sci-Fi'], ['Action', 'Comedy', 'Drama'], ['Action', 'Drama', 'History'], ['Animation', 'Action', 'Adventure'], ['Comedy'], ['Crime', 'Drama', 'Thriller'], ['Animation', 'Comedy'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Thriller'], ['Animation', 'Action', 'Adventure'], ['Comedy'], ['Animation', 'Comedy'], ['Drama'], ['Drama', 'Mystery'], ['Comedy', 'Music'], ['Documentary', 'Comedy'], ['Comedy', 'Drama'], ['Animation', 'Action', 'Adventure'], ['Crime', 'Drama', 'History'], ['Animation', 'Action', 'Adventure'], ['Crime', 'Drama', 'Mystery'], ['Animation', 'Comedy', 'Drama'], ['Adventure', 'Drama', 'Western'], ['Documentary', 'Talk-Show'], ['Documentary', 'Crime'], ['Action', 'Adventure', 'Drama'], ['Drama', 'Horror', 'Mystery'], ['Crime', 'Drama'], ['Comedy'], ['Comedy', 'Drama'], ['Crime', 'Drama', 'Mystery'], ['Drama', 'History'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Drama', 'Thriller'], ['Comedy', 'Talk-Show'], ['Drama', 'Romance'], ['Animation', 'Crime', 'Drama'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Drama', 'Mystery'], ['Comedy'], ['Animation', 'Action', 'Adventure'], ['Animation', 'Action', 'Comedy'], ['Action', 'Drama', 'History'], ['Crime', 'Mystery', 'Thriller'], ['Comedy', 'Talk-Show'], ['Action', 'Adventure', 'Mystery'], ['Animation', 'Short', 'Comedy'], ['Action', 'Crime', 'Drama'], ['Comedy'], ['Comedy', 'Drama', 'Romance'], ['Animation', 'Action', 'Adventure'], ['Documentary', 'Crime'], ['Comedy', 'Drama', 'Music'], ['Comedy'], ['Drama', 'Romance'], ['Action', 'Crime', 'Drama'], ['Animation', 'Action', 'Adventure'], ['Drama', 'History', 'War'], ['Crime', 'Drama', 'Thriller'], ['Drama'], ['Action', 'Comedy'], ['Animation', 'Comedy'], ['Documentary', 'Adventure'], ['Documentary'], ['Comedy', 'Drama'], ['Animation', 'Action', 'Adventure'], ['Comedy', 'Game-Show'], ['Drama', 'Sport'], ['Adventure', 'Drama', 'Family'], ['Comedy'], ['Comedy'], ['Crime', 'Drama', 'Mystery'], ['Comedy'], ['Adventure', 'Comedy', 'Drama'], ['Family', 'Fantasy', 'Music'], ['Comedy', 'Drama'], ['Drama', 'Romance'], ['Animation', 'Action', 'Adventure'], ['Drama'], ['Action', 'Crime', 'Drama'], ['Comedy', 'Music', 'Musical'], ['Comedy'], ['Animation', 'Action', 'Drama'], ['Documentary'], ['Crime', 'Drama', 'Mystery'], ['Drama', 'War'], ['Animation', 'Action', 'Adventure'], ['Crime', 'Drama', 'Mystery'], ['Comedy', 'Drama'], ['Documentary', 'Biography', 'Crime'], ['Crime', 'Drama', 'History'], ['Comedy'], ['Animation', 'Action', 'Adventure'], ['Animation', 'Action', 'Adventure'], ['Biography', 'Drama', 'History'], ['Comedy', 'Talk-Show'], ['Comedy', 'Sci-Fi'], ['Comedy'], ['Crime', 'Drama'], ['Comedy', 'Crime', 'Drama'], ['Comedy', 'Drama'], ['Comedy', 'Romance'], ['Animation', 'Action', 'Adventure'], ['Crime', 'Drama', 'Mystery'], ['Action', 'Adventure', 'Crime'], ['Animation', 'Action', 'Adventure'], ['Comedy'], ['Animation', 'Action', 'Adventure'], ['Crime', 'Drama', 'Thriller'], ['Comedy', 'Family'], ['Documentary', 'History', 'War'], ['Biography', 'Drama'], ['Comedy'], ['Comedy', 'Musical', 'Sci-Fi'], ['Animation', 'Comedy', 'Drama'], ['Documentary', 'Sport'], ['Comedy', 'Game-Show'], ['Action', 'Adventure', 'Drama'], ['Comedy', 'Reality-TV'], ['Animation', 'Action', 'Adventure'],  ['Drama', 'Romance'], ['Crime', 'Drama', 'Horror'], ['Comedy'], ['Comedy', 'Drama', 'Family'], ['Crime', 'Drama', 'Thriller'], ['Crime', 'Drama', 'Mystery'], ['Animation', 'Drama', 'Fantasy'], ['Action', 'Adventure', 'Biography'], ['Comedy', 'Drama'], ['Drama', 'Fantasy', 'Romance'], ['Action', 'Crime', 'Mystery'], ['Crime', 'Drama', 'Thriller'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Drama', 'Thriller'], ['Drama', 'Mystery', 'Sci-Fi'], ['Drama', 'Sci-Fi', 'Thriller'], ['Animation', 'Comedy', 'Sci-Fi'], ['Crime', 'Drama', 'Mystery'], ['Drama', 'Thriller'], ['Comedy'], ['Drama'], ['Comedy'], ['Animation', 'Action', 'Crime'], ['Biography', 'Crime', 'Drama'], ['Biography', 'Drama', 'History'], ['Comedy'], ['Action', 'Adventure', 'Biography'], ['Action', 'Comedy', 'Fantasy'], ['Crime', 'Drama'], ['Crime', 'Drama'], ['Crime', 'Drama'], ['Comedy', 'Drama', 'Romance'], ['Animation', 'Action', 'Adventure'], ['Animation', 'Action', 'Family'], ['Drama'], ['Animation', 'Comedy', 'Sci-Fi'], ['Action', 'Drama', 'History'], ['Crime', 'Drama', 'Mystery'], ['Crime', 'Drama'], ['Comedy', 'News', 'Talk-Show'], ['Animation', 'Action', 'Adventure'], ['Animation', 'Action', 'Adventure'], ['Drama', 'Mystery', 'Thriller'], ['Comedy', 'News', 'Talk-Show'], ['Comedy', 'Fantasy', 'Horror'], ['Drama', 'Fantasy', 'Mystery'], ['Adventure', 'Fantasy'], ['Animation', 'Action', 'Adventure'], ['Comedy', 'Crime'], ['Crime', 'Drama'], ['Comedy', 'Drama'], ['Drama', 'Mystery', 'Sci-Fi'], ['Comedy', 'Drama'], ['Comedy', 'Talk-Show'], ['Drama'], ['Animation', 'Family', 'Comedy'], ['Comedy', 'Horror'], ['Comedy', 'Drama'], ['Drama'], ['Documentary', 'Short'], ['Crime', 'Drama', 'Mystery'], ['Comedy', 'Romance'], ['Comedy', 'Family', 'Music'], ['Drama', 'Mystery', 'Sci-Fi'], ['Comedy', 'Crime']]
unique_genres = sorted({i for j in all_genres for i in j})
genre_matrix = []
for i in unique_genres:
temp = []
for j in unique_genres:
s = sum(1  if i in m and j in m and i!=j else 0 for m in all_genres)
temp.append(s)
genre_matrix.append(temp)
genre_matrix = np.array(genre_matrix)

ax = sns.heatmap(genre_matrix, xticklabels=unique_genres, yticklabels=unique_genres, annot=True, linewidths=.42, cbar=True, cbar_kws={'label': 'Colorbar'})
#plt.savefig('seaborn_cross_fold_plot.png', bbox_inches="tight", pad_inches=0)
plt.show()
Das resultierende Bild ist dieses:
Image


Ich möchte nur den unteren oder unteren Teil dieser Heatmap erhalten, da der linke untere Teil und der obere rechte Teil gleich wären, d. h. sie sind nur eine Spiegelung der diagonalen Linie. Das resultierende Bild, das ich erhalten möchte, sieht etwa so aus:

Image


Wie macht man das in Seaborn oder in Matplotlib?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post