Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib中的并排绘图_Python_Pandas_Matplotlib - Fatal编程技术网

Python matplotlib中的并排绘图

Python matplotlib中的并排绘图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有以下2个dfs,它们是指数和泊松图 import pandas as pd import numpy as np import matplotlib.pyplot as plt mean = 2 step = 0.5 df1 = pd.DataFrame() df1['A'] = pd.Series(abs(np.random.exponential(step, 400))) df2 = pd.DataFrame() df2['B'] = pd.Series(abs(np.random.p

我有以下2个
df
s,它们是指数和泊松图

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

mean = 2
step = 0.5
df1 = pd.DataFrame()
df1['A'] = pd.Series(abs(np.random.exponential(step, 400)))
df2 = pd.DataFrame()
df2['B'] = pd.Series(abs(np.random.poisson(mean, 400)))

df1_summ = df1_summary[['A']].groupby(['A']).size().reset_index(name='counts')
df1_summ = df1_summ.sort_values(['counts'], ascending=True)
df2_summ = df2[['B']].groupby(['B']).size().reset_index(name='counts')
在Jupyter笔记本中,我希望将它们并排绘制。但是,下面的代码不允许这样做。我该怎么修

plt.figure(1)
plt.subplot(221)
df1_summ.plot.bar(x='A', y='counts', figsize=(5, 4), title='Exponential Plot')

plt.figure(2)
plt.subplot(222)
df2_summ.plot.bar(x='B', y='counts', figsize=(5, 4), title='Poisson Plot')

plt.show()

只需创建一个地物,然后创建子地块并将其作为参数传递给plotting函数:

plt.figure(1)
ax1 = plt.subplot(221)
df1_summ.plot.bar(x='A', y='counts', ax=ax1, figsize=(5, 4), title='Exponential Plot')

ax2 = plt.subplot(222)
df2_summ.plot.bar(x='B', y='counts', ax=ax2, figsize=(5, 4), title='Poisson Plot')
作为替代方案

fig = plt.figure()
fig.set_figheight(20) # optional setting the height of the image
fig.set_figwidth(20) # optional setting the width of the image

a = fig.add_subplot(1,2,1)
df1_summ.plot.bar(x='A', y='counts')
a.set_title=('Exponential Plot')
plt.axis('off') # removes plots on axis

a = fig.add_subplot(1,2,2)
df2_summ.plot.bar(x='B', y='counts')
a.set_title=('Poisson Plot')
plt.axis('off') #romoves plots on axis

我有一个扩展问题。在这种情况下,如何更新地物图的大小?抱歉,我将使用
figsize
属性回答…问题