0

I am trying to specify a common X and Y axis label that spans 4 subplots (1 col), but get the error: "'numpy.ndarray' object has no attribute 'set_ylabel'"

This code works without an issue when I am just creating a single graph/axis. Code is pasted below. Currently in a jupyter notebook

# set format specifications 
sns.set(context='notebook', style='white', font='sans-serif', font_scale=1.5, 
        rc={"lines.linewidth":2})

# palette colors to be used in graphs
colors = ["#ff24db", "#023eff", "#24dbff", "#fe9200"]

# create figure and set title
f, ax = plt.subplots(4, sharex=True, sharey=True, figsize=(10,8))
f.suptitle('Solvent Swap EX (Liquid Level over Time)', fontsize=20, weight='bold')

# plot every 10th datapoint from each run; data is parsed from JSON and stored in 1st element of tuple
sns.lineplot(x='Minutes', y='LevelValue', data=run1[0].iloc[::10], color=colors[0], label="Run 1", ax=ax[0])
sns.lineplot(x='Minutes', y='LevelValue', data=run2[0].iloc[::10], color=colors[1], label="Run 2", ax=ax[1])
sns.lineplot(x='Minutes', y='LevelValue', data=run3[0].iloc[::10], color=colors[2], label="Run 3", ax=ax[2])
sns.lineplot(x='Minutes', y='LevelValue', data=run4[0].iloc[::10], color=colors[3], label="Run 4", ax=ax[3])

# plot tolerance lines from each run; data is stored in 3rd element of tuple
ax[0].axhline(1 - run1[2][0], color='gray',ls='--', linewidth=1.5, alpha=.7) # tol line
ax[1].axhline(1 - run2[2][0], color='gray',ls='--', linewidth=1.5, alpha=.7) # tol line
ax[2].axhline(1 - run3[2][0], color='gray',ls='--', linewidth=1.5, alpha=.7) # tol line
ax[3].axhline(1 - run4[2][0], color='gray',ls='--', linewidth=1.5, alpha=.7) # tol line

sns.despine(left=True)

# ax.set(ylim=(0.0, 0.9))

# ax.set_title('Solvent Swap EX', fontsize=20, weight='bold')
ax.set_ylabel('Relative Height', weight='bold')
ax.set_xlable('Time (minutes)', weight='bold')

# plt.savefig('./EX_21_multiGraph.png', transparent=True, dpi=300, bbox_inches = "tight")
plt.show();

Click for graph

  • `ax` is an ndarray containing the subplots, see [here](https://stackoverflow.com/questions/37967786/axes-from-plt-subplots-is-a-numpy-ndarray-object-and-has-no-attribute-plot) for example. – BigBen Mar 20 '20 at 16:41
  • When posting a question about code that produces an Exception, always include the complete Traceback - copy and paste it then format it as code (select it and type `ctrl-k`) – wwii Mar 20 '20 at 16:44
  • 3
    Does this answer your question? [pyplot axes labels for subplots](https://stackoverflow.com/questions/6963035/pyplot-axes-labels-for-subplots) ... or [Common xlabel/ylabel for matplotlib subplots](https://stackoverflow.com/questions/6963035/pyplot-axes-labels-for-subplots) – wwii Mar 20 '20 at 16:48

0 Answers0