I am trying to plot a bar chart and a line overlay, where my data has datetime as an index. This is the code:
import pandas as pd
import numpy as np
dates = pd.date_range('2019-01-01', '2019-01-31', freq='B')
df = pd.DataFrame(index=dates,
columns=['a', 'b', 'c'],
data = np.random.randn(len(dates), 3))
fig, ax = plt.subplots()
df.plot.bar(ax=ax)
df.sum(axis=1).plot(ax=ax)
Unfortunately, it only ends up showing the last chart requested.
I'm using
python 3.6.8
pandas 0.24.0
matplotlib 3.0.2
Regards
Following the comment by @ImportanceOfBeingErnest I think the best way to answer this is to use the use_index=False
kwarg.
For the data format etc, this is another problem and depends on what one wants to achieve.
import pandas as pd
import numpy as np
dates = pd.date_range('2019-01-01', '2019-01-31', freq='B')
df = pd.DataFrame(index=dates,
columns=['a', 'b', 'c'],
data = np.random.randn(len(dates), 3))
fig, ax = plt.subplots()
df.plot.bar(ax=ax)
df.sum(axis=1).plot(ax=ax, use_index=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With