熊猫情节22个系列中的11个地块中的1个图

时间:2018-04-06 07:42:00

标签: python pandas plot

我可以在11个图形和1个图形中绘制11个系列:

NG = [1,2,3,4,5,6,7,8,9,10,11]
serieslist = []

for n in NG:
    l = [1,2,3,4,5,6]
    df = pd.DataFrame(l)
    serieslist.append(df)

df = pd.concat(serieslist, axis = 1)
df.plot(grid = 1, subplots = True, layout = (6,2), sharey = True)

enter image description here

如何在1个图中绘制22个系列(其中2个应始终在一个图中)?这意味着11个图中的22个图。以下代码仅提供22个图表:

NG = [1,2,3,4,5,6,7,8,9,10,11]
serieslist = []

for n in NG:
    l = [1,2,3,4,5,6]
    df = pd.DataFrame(l)
    serieslist.append(df)
    serieslist.append(df)


df = pd.concat(serieslist, axis = 1)
df.plot(grid = 1, subplots = True, layout = (12,2), sharey = True)

enter image description here

编辑: 这不是我想要的解决方案的100%,但它看起来更漂亮:

import pandas as pd

NG = [1,2,3,4,5,6,7,8,9,10,11]
dflist1 = []
dflist2 = []

l = [1,2,3,4,5,6]
b = [6,5,4,3,2,1]


for n in NG:
    df = pd.DataFrame(l)
    dflist1.append(df)
    df = pd.concat(dflist1, axis = 1)
    df2 = pd.DataFrame(b)
    dflist2.append(df2)
    df2 = pd.concat(dflist2, axis = 1)

df.plot(grid = 1, subplots = True, layout = (12,1), sharey = True)
df2.plot(grid = 1, subplots = True, layout = (12,1), sharey = True)

输出:2位数。现在如何将这些图组合成1个数字?

enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用此matplotlib.pyplot.subplot

 import matplotlib.pyplot as plt 

在一个单元格中:

  • 迭代值i in range(11)
  • 在迭代中 i
    • 致电plt.subplot(6, 2, i + 1)
    • 绘制由输入ii +
    • 组成的DataFrame