- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在同一输出中创建两个子图。但是我在尝试创建 ax.1 和 ax.2 时收到 Type Error: 'AxesSubplot' object is not iterable
下面是代码示例和我尝试做的事情。
import numpy as np
import matplotlib.pyplot as plt
#plot 1 data
x1_data = np.random.randint(80, size=(400, 4))
y1_data = np.random.randint(80, size=(400, 4))
#plot 2 data
x2_data = np.random.randint(80, size=(400, 4))
y2_data = np.random.randint(80, size=(400, 4))
fig, (ax1, ax2) = plt.subplots(figsize = (8,6))
#scatter plot 1
scatter1 = ax1.scatter(x1_data[0], y1_data[0])
#scatter plot 2
scatter2 = ax2.scatter(x2_data[0], y2_data[0])
plt.draw()
我尝试了 .add_subplot()
但得到了同样的错误?
最佳答案
您需要指定其中一个
>>> plt.subplots(2, 1, figsize=(8,6))
或
>>> plt.subplots(1, 2, figsize=(8,6))
否则,只会返回一个 Axes
,而您正试图对其进行可迭代的拆包,这是行不通的。
call signature是 subplots(nrows=1, ncols=1, ...)
。
>>> fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 6))
>>> scatter1 = ax1.scatter(x1_data[0], y1_data[0])
>>> scatter2 = ax2.scatter(x2_data[0], y2_data[0])
或者,您可以使用 .add_subplot()
。首先创建一个 Figure,然后添加到它:
>>> fig = plt.figure(figsize=(8, 6))
>>> ax1 = fig.add_subplot(211)
>>> ax2 = fig.add_subplot(212)
>>> ax1.scatter(x1_data[0], y1_data[0])
>>> ax2.scatter(x2_data[0], y2_data[0])
关于python - 类型错误 : 'AxesSubplot' object is not iterable when trying to create 2 subplots,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49246747/
我正在尝试了解 matplotlib API。我见过很多这样的例子: ... fig, (ax0, ax1) = plt.subplots(nrows=2) ax1.spines['right'].s
我正在尝试运行来自 here 的 basemap 示例我面临错误“AxesSubplot”对象没有属性“get_axis_bgcolor”。当我从该站点尝试第一个示例时,我应该收到黑色、水蓝色和陆地珊
我绘制了来自 pandas 的一些数据DataFrame在 Jupyter notebook像这样的单元格: ax = data.plot('Weight', 'Height', kind='
使用 python 2.7x,无法升级,因为我使用的是托管 Windows 系统。我尝试按照此示例合并子图,但返回以下错误: 'AxesSubplot' object has no attribute
这个问题在这里已经有了答案: understanding matplotlib.subplots python [duplicate] (1 个回答) 关闭 4 年前。 我正在尝试制作包含在两个数据
我想从从 pandas.Series.hist 返回的 matplotlib.axes.AxesSubplot 中获取值方法。有什么方法可以这样做吗?我在列表中找不到该属性。 import panda
所以我正在尝试使用 Axes 对象来控制我的 matlibplot 图。我没有使用 plt(又名 import matlibplot.pyplot as plt),因为我根据 this 将图形嵌入到我
我有一个对象 fig2,它是一个类 mathplotlib.axes.axessubplot,但是当我尝试执行 fig2.show() 时,python 说 axessubplot 对象没有属性显示。
在寻找Matplotlib get subplot (axes) size?的答案,我意识到 ax1、ax2 变量属于 AxesSubplot 类。 但是,我在任何地方都找不到关于此的任何文档 - 例
有什么方法可以获取指向子图中的 AxesImage 实例的指针吗?例如,在一般情况下,例如: import matplotlib.pyplot as plt import numpy as np da
不确定如何修复以下属性错误: AttributeError: 'AxesSubplot' object has no attribute 'add_axes' 问题似乎与我设置情节的方式有关: gri
代码 import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) print type(ax) 给出输出
我想绘制一个堆叠条形图,其中的数据来自 Pandas 中的两个独立数据框(My_means 和 My_stds)。我正在使用 Python 3.7。 绘图调用工作正常,但是,标签被切断。设置 tiny
我正在使用导入为 PL 的 matplotlib.pyplot 制作绘图: FIG = PL.figure(figsize=(12,8), dpi=150) AX = FIG.add_subplot(
import pandas as pd import matplotlib.pyplot as plt file = 'd:\\a\\pandas\\test.xlsx' data = pd.Exce
查看 matplotlib 文档,似乎将 AxesSubplot 添加到 Figure 的标准方法是使用 Figure。添加子图: from matplotlib import pyplot fig
我换了一台新电脑,安装了Python3.6和matplotlib,上个月在旧电脑上运行代码时,出现如下错误: ax.hold(真) AttributeError: 'AxesSubplot' 对象没有
看着matplotlib文档,这似乎是添加 AxesSubplot 的标准方法到 Figure是使用 Figure.add_subplot : from matplotlib import pyplo
查看 matplotlib 文档,似乎将 AxesSubplot 添加到 Figure 的标准方法是使用 Figure。 add_subplot: from matplotlib import pyp
我正在尝试将轨道模拟嵌入到 tkinter 框架中,我的绘图工作正常我现在只是尝试将圆圈输入到图表中以表示行星。我查看了有关如何在 FigureCanvasTkAgg 中绘制圆圈的文档,但找不到任何内
我是一名优秀的程序员,十分优秀!