How to rescale only one y-axis in seaborn catplot and add data labels

2.9k Views Asked by At

I have created a catplot for number of people killed/injured using the catplot function. However, since the scales of the 2 are very different the bars in second graphs are very small and cannot be read. Anyway I can re-scale y-axis of the second chart? And add data labels to both charts?

grid = sns.catplot(x = 'borough',
            y = 'Injured/Killed',
            hue = 'Commuter Type',
            col = 'Injury Type',
            data = tabular_breakdown,
            kind = 'bar')

catplot output (image)

1

There are 1 best solutions below

0
On

To solve your issue, there are two things to consider.

  1. The call to catplot has as the default, sharey=True, so whatever you changed in the second axes would reflect on the other.
  2. You have to access the two axes in order to adjust them. They are contained in grid, so no problem.

To solve the first issue, pass your call with sharey=False. To solve the second, access the axes with something like ax0, ax1 = grid.axes[0], then call ax1.set_ylim(<values>). If you don't want to specify sharey=False, which is what I was going for initially, you're going to have to resort to the solutions here.