【问题标题】:'numpy.ndarray' object has no attribute 'plot' [duplicate]“numpy.ndarray”对象没有属性“plot”[重复]
【发布时间】:2021-05-07 01:07:04
【问题描述】:

问题:填写下面的代码以可视化所有 100 种蛋白质表达。

这是我的代码。我不知道为什么它一直显示 'numpy.ndarray' 对象没有属性 'plot'

fig, ax = plt.subplots(10,10,figsize=(15,15), sharex=True, sharey=True)
for i, protein in enumerate(PROTEIN_NAMES):
    ax[i].plot(young_df[i], label="Young", alpha=0.6)
    ax[i].plot(old_df[i], label="Old", alpha=0.6)
    continue
fig.text(0.5, 0.04, 'Sample number', ha='center', va='center')
fig.text(0.06, 0.5, 'Expression Value', ha='center', va='center', rotation='vertical')

【问题讨论】:

  • 错误告诉你问题是什么; ax[i] 是一个 numpy 数组,而 numpy 数组没有 plot 方法
  • 请参阅this 文档下方的示例,其中有以下行:f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)

标签: python numpy numpy-ndarray subplot


【解决方案1】:

我认为问题在于,斧头是二维图,因此您必须像这样将protein 添加到循环中

fig, ax = plt.subplots(10,10,figsize=(15,15), sharex=True, sharey=True)
for i, protein in enumerate(PROTEIN_NAMES):
    ax[i, protein].plot(young_df[i], label="Young", alpha=0.6)
    ax[i, protein].plot(old_df[i], label="Old", alpha=0.6)
    continue
fig.text(0.5, 0.04, 'Sample number', ha='center', va='center')
fig.text(0.06, 0.5, 'Expression Value', ha='center', va='center', rotation='vertical')

【讨论】:

    猜你喜欢
    • 2016-11-01
    • 1970-01-01
    • 2019-11-09
    • 2016-10-24
    • 2020-09-22
    • 2020-02-21
    • 2020-12-08
    • 2019-12-10
    相关资源
    最近更新 更多