2

I created a heatmap using Seaborn library. I am struggling to do the text wrapping on the X and Y axis tick labels. This is how my code looks like:

d = {'col1': ['HELLO!', 'Hellooo I am Looong', 'Am I loooooooooooooooooooooooooooong enough?','Probably Noooooooooooooooooooooooooooooooooooooo!!!'], 'col2': ['I want to go to London', 'I want to go to London and Paris',' I dont want to goooooooo anywhere', 'I want to sleep on my beeeeeeeeeeeeeeed!!'], 'values':[20,30,50,90]}
df = pd.DataFrame(data=d)
hmp = pd.pivot_table(df, values='values', index=['col1'],
                    columns=['col2'], aggfunc=np.mean)

fig, ax = plt.subplots(figsize = (8,6), dpi=260)
import matplotlib.colors as mcolors

cmap = mcolors.LinearSegmentedColormap.from_list("n",['#004c4c','#008080','#b2d8d8','#ffb7b7','#ff3838','#a50000'])
norm = plt.Normalize(df['values'].min(),df['values'].max())
sns.heatmap(hmp,linewidths=0.75, cmap=cmap, norm=norm)


plt.xticks(rotation=45, ha="right",
         rotation_mode="anchor", size=8.5)
plt.ylabel("Major Diagnostic Categories") 
plt.xlabel("Provider Servicing Name")
plt.title("Wrap labels around X and Y axis",fontweight="bold", size=14.5) ## Plot title
plt.show()

Please guide me on how I can resolve this issue. Thanks! enter image description here

Deepansh Arora
  • 724
  • 1
  • 3
  • 15

0 Answers0