Home > Net >  How to add custom ticks on the right of a heatmap
How to add custom ticks on the right of a heatmap

Time:10-01

Given the following sample data

data =\
{'q1': [6, 4, 4, 4, 6, 6, 6, 4, 6, 6, 6, 6],
 'q2': [3, 3, 3, 4, 3, 3, 4, 3, 4, 3, 4, 1],
 'q3': [6, 3, 4, 4, 4, 4, 6, 6, 6, 6, 4, 1],
 'q4': [3, 6, 6, 6, 6, 6, 4, 4, 6, 4, 6, 4],
 'q5': [4, 3, 3, 3, 3, 6, 6, 4, 4, 6, 3, 4],
 'q6': [3, 3, 4, 4, 6, 3, 3, 1, 6, 4, 4, 4],
 'q7': [4, 3, 3, 3, 3, 6, 4, 1, 4, 1, 4, 1],
 'q8': [4, 4, 1, 6, 4, 6, 4, 1, 6, 1, 4, 1],
 'q9': [4, 6, 4, 3, 4, 3, 4, 6, 6, 4, 3, 4],
 'q10': [3, 4, 1, 3, 4, 3, 3, 6, 6, 3, 4, 4]}

Here is my code:

import seaborn as sns
import pandas as pd

df = pd.DataFrame(data)

cm = sns.heatmap(df.T, annot=False, cbar=True)

cm.get_figure().savefig('heatmap.pdf')

And here is the output:

output

What I'm trying to do is add custom y-axis ticks on the right, something like this:

desired_output

How can I do this? I looked into using tick_params as suggested enter image description here

  • Related