Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I dont think you need all the code to help me with this, this was working 3 months ago but now the subplots are not getting added to the same figure. i.e. I want one figure 2 by 2 populated with a different line chart for each of the 4 countries in my table. what i currently get is one figure with 4 empty charts and 4 subsequent individual charts. why is this not getting adding to the same chart correctly now?

I have upgraded python and pandas since that time and anaconda(spyder) which I use. I am currently using the following versions:

Python 2.7.5 |Anaconda 1.8.0 (64-bit) Matplotlib 1.3.1 Pandas 0.15.2

for i, group in df.groupby('Country'):
   chrt += 1 
   fig1.add_subplot(2,2, chrt)
   #fig1.subplots_adjust(hspace=1)
   group.plot(x='Month', y='Value (USD)',title= str(i))
share|improve this question
    
What kind of object is group? (For the group.plot) I am not a python expert, but usually what I do when plotting is something more like ax=fig1.add_subplot(...), then ax.plot( ... something involving group ... ) – TravisJ Apr 16 '15 at 13:33
    
Thanks TravisJ, I guess I was just struggling to get the ( ... something involving group ... ) in when i was using the ax=fig1....method. – IcemanBerlin Apr 16 '15 at 13:48
up vote 1 down vote accepted

A few things come to mind. Make sure fig1 and chrt are well initialized. Then, you can specify which axis it plots on with the ax keyword.

import matplotlib.pyplot as plt
fig1 = plt.figure()
chrt = 0
for i, group in df.groupby('Country'):
    chrt += 1 
    ax = fig1.add_subplot(2,2, chrt)
    group.plot(x='Month', y='Value (USD)',title=str(i), ax=ax)
share|improve this answer
    
thanks @Julien Spronck the ax=ax was the trick I hadnt tried, still dont understand it all but it works. – IcemanBerlin Apr 16 '15 at 13:49
    
you're welcome :-) – Julien Spronck Apr 16 '15 at 13:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.