-1

Questions: Fill in the code below to visualize all 100 protein expressions.

Here is my code. I don't know why it keeps showing 'numpy.ndarray' object has no attribute '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')
Travis Teo
  • 19
  • 3
  • the error tells you what the problem is; `ax[i]` is a numpy array, and numpy arrays don't have a `plot` method – G. Anderson Feb 02 '21 at 20:02
  • See [this](https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.subplots.html) document down in the example where there is this line: `f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)`. – Mike O'Connor Feb 02 '21 at 20:05

1 Answers1

-1

I think that the problem is, that the ax is a 2 dimensional plot, so you would have to add the protein into the loop like this

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')
Oliver Hnat
  • 797
  • 4
  • 19