I am testing the capabilities of pandas to plot financial data (price and volume) on the same chart. If I try to render both data as lines, it works fine:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
a = pd.date_range('2019-01-01', '2019-06-01',freq = 'D')
b = np.random.normal(size = len(a), loc = 50)
v = np.random.normal(size = len(a), loc = 1000)
c = pd.DataFrame(index = a, data = zip(b,v), columns = ['price', 'volume'])
fig, ax = plt.subplots(figsize = (15,8))
bx = ax.twinx()
c.price.plot.line(ax = ax, color = 'r')
c.volume.plot.line(ax = bx, color = 'g', alpha = .2)
plt.show()
However if I try to render one as a line and the other as a bar chart, by replacing the 3 last lines by:
c.price.plot.line(ax = ax, color = 'r')
c.volume.plot.bar(ax = bx, color = 'g', alpha = .2)
plt.show()
Would anybody know how to make the above code work with line + bar ??