I'm using pandas to plot some data.
If I plot this:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'a': [100, 200, 150, 175],
'b': [430, 30, 20, 10]})
fig, ax1 = plt.subplots(figsize=(15, 10))
df['b'].plot(kind='bar', color='y')
df['a'].plot(kind='line', marker='d')
Everything plots fine.
If I plot the bar axis on the secondary axis, the bar plot will be in front of the line plots, obstructing the lines from being viewed, like this.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'a': [100, 200, 150, 175],
'b': [430, 30, 20, 10]})
fig, ax1 = plt.subplots(figsize=(15, 10))
df['b'].plot(kind='bar', color='y', secondary_y=True)
df['a'].plot(kind='line', marker='d')
How do I make a bar plot/line plot where...
- Using pandas/matplotlib
- Bar plot is on secondary axis and line chart is on primary axis
- Line plots are in front of the bar plot




plot()function of aDataframealso has thezorderkeyword; you could try setting that to some high value in your second example.