0

hi I would like to know if there is a way to get matplotlib.pyplot.subplots() to always be subscriptable. for example:

fig, ax = plt.subplots(nrows=2, ncols=2)
ax[0,0].plot([1,2,3],[2,4,8])

The code above works as expected, but if I change the number of rows and cols to 1 I get

ax[0,0].plot([1,2,3],[2,4,8])
TypeError: 'AxesSubplot' object is not subscriptable

which is normally ok, but I don't want to change all instances of ax[0,0] to ax everytime I want to plot one graph.

Trenton McKinney
  • 43,885
  • 25
  • 111
  • 113
user169808
  • 423
  • 1
  • 5
  • 23

0 Answers0