python-3.x - 在 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.ax
是ndarray
根据错误。由于 的名称ax
,假设它是一个Axis
对象数组是合理的,因此您将需要调用get_figure
数组项,而不是实际的数组。
推荐阅读
- c# - 等到元素显示的方法,但需要将元素作为参数传递,使其成为要使用的通用方法
- ios - 尝试从更新前仅包含 27 个项目的第 0 节中删除项目 30
- ios - 将参数附加到 NSURLSession 委托方法
- vb.net - System.Windows.Forms.dll 中出现“System.InvalidOperationException”类型的第一次机会异常
- java - doPost() 没有看到参数
- php - 使用 Or-Tools 的车辆路线问题 - 自动决定初始起点
- reactjs - 反应高图表不显示情节线
- javascript - 如何从内部图像onLoad返回变量
- c# - c#:通过电子邮件批准/拒绝:不是按钮:最少点击
- jquery - 卡在带有复选框的jquery中