python - Arrange line in front of bars in Matplotlib plot with double y axes -
i want plot graph 2 y axes, , want left y axis show line according x axis sorted, , right y axis show bars. problem secondary y axis hides first y axis, shown in attached figure. code use following:
import matplotlib import matplotlib.pyplot plt matplotlib.ticker import scalarformatter fig, ax1 = plt.subplots() ax2 = ax1.twinx() p1 = ax1.plot(ind, total_facilities, '--bo') width = 1 p2 = ax2.bar(ind, pdb_facilities, width, color='gray',edgecolor = "none") plt.xlim([-1,len(total_facilities)]) ax1.set_yscale('symlog') when re-arrange axes plot blue line in secondary axis line goes in front of gray bars it's confusing because want x-axis ordered according values of primary y axis. there way bring blue line in front while keeping in primary y axis?

i found can switch place of secondary y axis, secondary y axis plotted on left , primary on right:
ax2 = ax1.twinx() p1 = ax2.plot(ind, total_facilities, '--bo') p2 = ax1.bar(ind, pdb_facilities, width, color='gray',edgecolor = "none") plt.xlim([-1,len(total_facilities)]) ax2.set_yscale('symlog') ax1.yaxis.tick_right() ax2.yaxis.tick_left() plt.show()
Comments
Post a Comment