在matplotlib中绘制数据帧数据



我有以下代码,用于在一个图中绘制两个数据帧数据

import pandas as pd
import numpy as np
from pprint import pprint
from matplotlib import pyplot as plt

df1 = pd.DataFrame(np.random.randn(10, 10))
df2 = pd.DataFrame(np.random.randn(10, 10))

plt.figure()
fig, axes = plt.subplots(nrows=1, ncols=1, squeeze=False)
df1.plot(ax=axes[0], style='o-')
axes[0].set_xlabel('x')
axes[0].set_ylabel('y')
axes[0].set_title('ttl')
df2.plot(ax=axes[0], style='--')
axes[0].set_xlabel('x')
axes[0].set_ylabel('y')
axes[0].set_title('ttl')

然而,我得到以下错误

fig = self.ax.get_figure()
AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'

任何关于如何解决这一问题的建议都将非常有用。

get_figure是Axis的一个方法,但根据错误,self.axndarray。由于ax的名称,可以合理地假设它是Axis对象的数组,因此需要调用数组项的get_figure,而不是实际的数组。

最新更新