Two y axes on the left side of the picture

I want to build curves with different y axis that have the same x axis. I used to use the twinx function, but they displayed them on different sides of the picture. Is there a way to build both of them on the left side. I'm looking for something like the following enter image description here

but on both sides on one side. The code for the above example is here .

In the other, no, is it possible to construct curves in a certain order, since the z-order does not work for twinx

+4
matplotlib
Nov 22 '13 at 13:58
source share
1 answer

Shown in red is the default behavior of twinx() . An additional modification of example applies to what is shown in green.

You can change both new axes, similar to green one, but select the left spine and apply a negative offset. Therefore, add / modify the example with:

 par1.spines["left"].set_position(("axes", -0.4)) # red one par2.spines["left"].set_position(("axes", -0.2)) # green one make_patch_spines_invisible(par1) make_patch_spines_invisible(par2) par1.spines["left"].set_visible(True) par1.yaxis.set_label_position('left') par1.yaxis.set_ticks_position('left') par2.spines["left"].set_visible(True) par2.yaxis.set_label_position('left') par2.yaxis.set_ticks_position('left') 

enter image description here

zorder from the lines is only taken into account in the axes (or does it appear so?), since you have separate axes one above the other, you have to change the zorder axes:

 host.set_zorder(1) par1.set_zorder(2) par2.set_zorder(3) 

Note that host has a white background, so placing it on top will hide other lines unless you set a transparent background.

+11
Nov 22 '13 at 14:21
source share



All Articles