0

Example DataFrame:

df = pd.DataFrame(data={'Amount':[10,20,30,40,50],
                        'Get':[111,222,333,444,555],
                        'Sum':[100,200,300,400,500]},
                  index=['Sun', 'Mon', 'The', 'Wed', 'Tue'])

Contents of df is now:

     Amount Get Sum
Sun     10  111 100
Mon     20  222 200
The     30  333 300
Wed     40  444 400
Tue     50  555 500

When I try draw two separate plots (skip second column 'Get') with dot notation like:

df['Amount'].plot()
df['Sum'].plot()

or in loop (in case I need filter some columns):

for i in range(df.shape[1]):
    if df.columns[i] in ['Amount', 'Sum']:
        df[df.columns[i]].plot()

I Received same graphic(figure):

plots image

But I need separate them to different figures. Yes I know I can create separated figure objects, but it is too complicated for simple case and must exist some separator for my case above (dot notated for DataFrame).

Vyacheslav
  • 77
  • 10
  • Does this answer your question? [How do I tell Matplotlib to create a second (new) plot, then later plot on the old one?](https://stackoverflow.com/questions/6916978/how-do-i-tell-matplotlib-to-create-a-second-new-plot-then-later-plot-on-the-o) – Nathan Furnal Nov 22 '20 at 15:04
  • @NathanFurnal is too complicated for my case. Yes I know how to draw plots using sublotss and figure objects. But dot notated case looks more simple and must have some separator. – Vyacheslav Nov 22 '20 at 15:12

1 Answers1

0

Try this:

df.plot(subplots=True);

enter image description here

Separate x-axis:

df.plot(subplots=True, sharex=False);

enter image description here

Scott Boston
  • 147,308
  • 15
  • 139
  • 187
  • Cool! One more new useful case for me! But In this case both graphics have same common X axis. Maybe possible fully separate them to independent images? – Vyacheslav Nov 22 '20 at 15:19
  • @Obelix add, `sharex=False` as parameter in plot. – Scott Boston Nov 22 '20 at 15:22
  • 1
    thanks. But how about if columns in DataFrame about 100? I mean, how to control\filter which ones use to show in this subplots? Why I ask to separate plots.. I think I can filter some columns in loop to show only those which I need. My main question doesn't reveal this case.. – Vyacheslav Nov 22 '20 at 15:30
  • Good question. I am not sure that can be done. I'll do a little research and see. If I find out anything, I'll post an update to this solution. – Scott Boston Nov 22 '20 at 15:32