matplotlib - Stuck with python multiple twinx axis graph using matlibplot -
hello i'm trying make graph 1 y axis , 4 x axis
i don't want make separate graphs , wondering if possible put multiple x axis using twinx() command.
the problem i'm having final axis i'm trying add ends appearing on both sides of graph , want on left.
from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist aa import matplotlib.pyplot plt host = host_subplot(111, axes_class=aa.axes) par1 = host.twinx() par2 = host.twinx() new_fixed_axis = par2.get_grid_helper().new_fixed_axis par2.axis["right"] = new_fixed_axis(loc="right",axes=par2,offset=(60, 0)) par2.axis["right"].toggle(all=true) host.set_xlabel("y axis") host.set_ylabel("x axis 1 on left") par1.set_ylabel("x axis 2 on right") par2.set_ylabel("x axis 3 on right") par3 = host.twinx() new_fixed_axis = par3.get_grid_helper().new_fixed_axis par3.axis["left"] = new_fixed_axis(loc="left",axes=par3,offset=(-60, 0)) par3.axis["left"].toggle(all=true) par3.set_ylabel("x axis 4 on left") p1, = host.plot([1,2,3,4],[1,2,3,4], label="1") p2, = par1.plot([1,2,3,4],[2,2,2,2], label="2") p3, = par2.plot([1,2,3,4],[3,3,2,1], label="3") p4, = par3.plot([1,2,3,4],[1,1,2.5,3.5], label="4") plt.show()
just set visibility false.
from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist aa import matplotlib.pyplot plt host = host_subplot(111, axes_class=aa.axes) plt.subplots_adjust(bottom=0.1, left=0.2, right=0.8, top=0.9) par1 = host.twinx() par2 = host.twinx() par3 = host.twinx() par3.axis["right"].set_visible(false) new_fixed_axis = par2.get_grid_helper().new_fixed_axis par2.axis["right"] = new_fixed_axis(loc="right",axes=par2,offset=(60, 0)) host.set_xlabel("y axis") host.set_ylabel("x axis 1 on left") par1.set_ylabel("x axis 2 on right") par2.set_ylabel("x axis 3 on right") par3.set_ylabel("x axis 4 on left") new_fixed_axis = par3.get_grid_helper().new_fixed_axis par3.axis["left"] = new_fixed_axis(loc="left",axes=par3,offset=(-60, 0)) p1, = host.plot([1,2,3,4],[1,2,3,4], label="1") p2, = par1.plot([1,2,3,4],[2,2,2,2], label="2") p3, = par2.plot([1,2,3,4],[3,3,2,1], label="3") p4, = par3.plot([1,2,3,4],[1,1,2.5,3.5], label="4") plt.show()
by way, when asking such question, helpful not reverse standard understanding of x-axis , y-axis! also, had add subplot_adjust
see whole figure mpl's standard settings.
Comments
Post a Comment