Python 在多个dataframe和列上显示dataframe子批次,在同一图形上显示相同的列
下面的代码分别显示了两个dataframe的列,如下图所示 如何在同一图表上显示相同的列Python 在多个dataframe和列上显示dataframe子批次,在同一图形上显示相同的列,python,pandas,dataframe,Python,Pandas,Dataframe,下面的代码分别显示了两个dataframe的列,如下图所示 如何在同一图表上显示相同的列 import numpy as np import pandas as pd import matplotlib.pyplot as plt # create dummy pandas dataframes pd1 = pd.DataFrame({'a':np.random.random(22),'b':np.random.random(22), 'c':np.ran
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# create dummy pandas dataframes
pd1 = pd.DataFrame({'a':np.random.random(22),'b':np.random.random(22),
'c':np.random.random(22)})
pd2 = pd.DataFrame({'a':np.random.random(22),'b':np.random.random(22),
'c':np.random.random(22)})
#create subplot figure with having two side by side plots
fig, axes = plt.subplots(nrows=3,ncols=2,figsize=(12,6))
# plot first pandas frame in subplot style
pd1.plot(ax = axes[:,0],subplots=True)
# plot second pandas frame in subplot style
pd2.plot(ax = axes[:,1],subplots=True)
plt.show()
试试:
fig, axes = plt.subplots(nrows=1,ncols=3,figsize=(12,6))
for c, ax in zip(pd1, axes):
pd1[c].plot(ax=ax, label=f'{c} pd1')
pd2[c].plot(ax=ax, label=f'{c} pd2')
ax.legend()
输出: