Jupyter如何绘制彼此相邻的2个dfs

时间:2018-02-02 22:11:45

标签: matplotlib plot jupyter-notebook

我试图在两个地块上绘制两个图,但是我找不到一个在我的情况下工作的图。大多数情况涉及了解子图如何工作。我希望有人能在这里解释一下。

以下是我在2个不同行上的2个不同图:

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

我最想要的是: enter image description here

我很确定从我读过的内容中我需要将它们变成子图,然后我可以将它们放在同一行上。不知道如何做到这一点。

1 个答案:

答案 0 :(得分:4)

subplots命令是设置它的最简单方法。

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 
相关问题