I am trying to combine a linear plot and a bar into one plot. The data source is the pandas framework.
Here is a demo:
import pandas as pd
test = {"index": range(10),
"line": [i**2 for i in range(10)],
"bar": [i*10 for i in range(10)]}
test=pd.DataFrame(test)
ax=test.plot(x="index",y="line")
test.plot(x="index",y="bar",color="r",kind="bar",ax=ax)
Everything is good so far, you can see that the line is above the bars. If I ask the barrel to use the secondary yaxis on the right, changing the last line as follows:
test.plot(x="index",y="bar",color="r",kind="bar",ax=ax, secondary_y=True)
Then the bars will be on top of the line that does not match me.
Here are two graphs:

I tried to build the bar first and then build the line, and I also tried to use zorderto force the line over the panel, but none of them work.
Any suggestions or help would be appreciated.
source
share