简体   繁体   中英

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

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')

猫图输出(图像)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM