Skip to content
Advertisement

Sharing Y-axis in a matplotlib subplots

I have been trying to create a matplotlib subplot (1 x 3) with horizontal bar plots on either side of a lineplot.

It looks like this: enter image description here

The code for generating the above plot –

JavaScript

Edit

How do I share the y-axis of the central line plot with the other horizontal bar plots?

Advertisement

Answer

I would set the limits of all y-axes to the same range, set the ticks in all axes and than set the ticks/tick-labels of all but the most left axis to be empty. Here is what I mean:

JavaScript

enter image description here

This is a minimal example and for the sake of conciseness, I refrained from mixing matplotlib and searborn. Since seaborn uses matplotlib under the hood, you can reproduce the same output there (but with nicer bars).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement