2

I tried to look a couple SO's on plotting 2 plots next to each other but I couldnt find one that worked in my case. Most of the cases involves understanding how subplot works. Which I'm hoping someone can explain here.

Here are my 2 distinct plots on 2 different rows:

import matplotlib.pyplot as plt
from matplotlib import six
import pandas as pd
import numpy as np

Size = pd.read_sql("select...".sort_values(['date'],ascending=True)

enter image description here

Cap = pd.read_sql("select...".sort_values(['date'],ascending=True)

enter image description here

What I would like to end up is this: enter image description here

I'm pretty sure from what I've been reading I need to make these into subplots then I can put them on the same row. Not sure how to do that though.

chowpay
  • 1,515
  • 6
  • 22
  • 44

1 Answers1

10

The subplots command is the easiest way to set that up.

fig, (ax1,ax2) = plt.subplots(1,2, figsize=(10,4))  # 1 row, 2 columns
df1.plot(..., ax=ax1)
df2.plot(..., ax=ax2)

plt.tight_layout()  # Optional ... often improves the layout 
iayork
  • 6,420
  • 8
  • 44
  • 49
  • That works pretty good but it makes both of my plots not very wide. So I tried to change the fig size on both but its ignored . For example d.plot(x='date', figsize=(6,4),rot=90, ax=ax1) no matter what I do to the 6,4 my plots still look the same – chowpay Feb 02 '18 at 22:32
  • So it looks like I can make them both larger if I change both. But if I change just one df's figsize then neither scale. – chowpay Feb 02 '18 at 22:39
  • 1
    Set figsize in the subplots call. See the updated version. If you want your plots to be different sizes, you'll need to use one of the `gridspec` variants (probably a separate question) – iayork Feb 02 '18 at 23:14