Python sns heatmap plot, need to show a text for legend y axis #2
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

So close, I need the names ['Tom', 'Dick', 'Sue','Ben'] to plot horizontally, not vertically. I realize the labels are used twice, not sure where best to place them.

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

test_data = {
'Java':[1,  5, 3, 3],
'COBOL':[2, 1, 1, 4],
'C':    [2, 3, 2, 1],
'C#':   [2, 2, 3, 2],
'.NET': [3, 1, 3, 4],
'Assembler':[3, 3, 2, 1],
'Python':  [ 4, 3, 3, 4]
}

labels = ["na", "poor", "average", "good", "excellent"]

df = pd.DataFrame(test_data)
plt.xticks(fontsize="9",rotation=45)
plt.yticks(fontsize="9")
plt.yticks(np.arange(4),['Tom', 'Dick', 'Sue','Ben'])
plt.yticks(rotation=45)

ax = sns.heatmap(df, cmap="YlGnBu", annot=False, yticklabels=(['Tom', 'Dick', 'Sue', "Ben"]))
cbar = ax.collections[0].colorbar
cbar.set_ticks([1, 2, 3, 4, 5])
cbar.set_ticklabels(labels)

plt.show()

Crowdsource coding tasks.

1 Solution

Winning solution

Solution

As you've requested, names are rotated horizontally.

The complete script can be found here: https://paste.ofcode.org/g5K3A8LMUuMjQYrGtZN3yk

Perfect, thank you!
broadreach 5 months ago