0

I have a conceptual problem in the basic structure of matplotlib. I want to add a Caption to a graph and I do understand the advice given in Is there a way of drawing a caption box in matplotlib However, I do not know, how to combine this with the pandas data frame I have. Without the structure given in the link above my code looks (projects1 being my pandas data frame):

ax2=projects1.T.plot.bar(stacked=True)
ax2.set_xlabel('Year',size=20)

and it returns a barplot. But if I want to apply the structure of above, I get stuck. I tried:

fig = plt.figure()
ax2 = fig.add_axes((.1,.4,.8,.5))
ax2.plot.bar(projects1.T,stacked=True)

And it results in various errors. So the question is, how do I apply the structure of the link given above with pandas data frame and with more complex graphs than a mere line. Thx

Community
  • 1
  • 1
Jan
  • 264
  • 1
  • 5
  • 14

1 Answers1

0

Pandas plot function has an optional argument ax which can be used to supply an externally created matplotlib axes instance to the pandas plot.

import matplotlib.pyplot as plt
import pandas as pd

projects1 = ...?

fig = plt.figure()
ax2 = fig.add_axes((.1,.4,.8,.5))

projects1.T.plot.bar(stacked=True, ax = ax2)
ax2.set_xlabel('Year',size=20)
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712