Home > Enterprise >  Matplotlib: control tick placement for categorical axis
Matplotlib: control tick placement for categorical axis

Time:10-16

There are several posts how to adjust tick placement if the axis is based on a numerical variable. How do you do this for an axis based on different (categorical) variables?

Example: Some outcome variable is measured in several subjects at week 1, 2, 3, and finally week 6.

df = pd.DataFrame(data=[[5, 4, 4, 3], [6, 4, 2, 3], [4, 4, 2, 1], 
                        [5, 4, 5, 2]], columns=['week1', 'week2', 'week3', 'week6'], 
                  index=['s1', 's2', 's3', 's4'])

The dataframe looks like this: plot text ticks using numeric distances

  • Related