Error message when using subplot in pyplot: ValueError: Illegal argument(s) to subplot: (2, 10)

Asked 2 years ago, Updated 2 years ago, 101 views

I'm a beginner who is practicing after reading a book by TensorFlow Golvin Hacker. I use the subplot of pyplot, but I wrote the same code as the book, but it emits an error message ㅜ 어떻게 Please help me with how to solve it.

Traceback (most recent call last):
  File "C:/Users/yym30/PycharmProjects/tensorflow/mnist/networks/autoencoder.py", line 69, in <module>
    fig, ax = plt.subplot(2, sample_size, figsize = (sample_size, 2))
  File "C:\Users\yym30\Anaconda3\envs\dl\lib\site-packages\matplotlib\pyplot.py", line 1072, in subplot
    a = fig.add_subplot(*args, **kwargs)
  File "C:\Users\yym30\Anaconda3\envs\dl\lib\site-packages\matplotlib\figure.py", line 1239, in add_subplot
    a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File "C:\Users\yym30\Anaconda3\envs\dl\lib\site-packages\matplotlib\axes\_subplots.py", line 72, in __init__
    raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
ValueError: Illegal argument(s) to subplot: (2, 10)

Process finished with exit code 1

This is the error message.

And this is the code that loads the subplot.

sample_size = 10
samples = sess.run(decoder, feed_dict={X:mnist.test.images[:sample_size]})

fig, ax = plt.subplot(2, sample_size, figsize = (sample_size, 2))

for i in range(sample_size):
    ax[0][i].set_axis_off()
    ax[1][i].set_axis_off()
    ax[0][i].imshow(np.reshape(mnist.test.images[i], (28,28)))
    ax[1][i].imshow(np.reshape(samples[i], (28, 28)))

plt.show()

Help me ㅜ<

python pyplot tensorflow

2022-09-21 15:56

1 Answers

plt.subplot(2, sample_size, figuresize=(sample_size, 2)) not plt.subplot(2, sample_size, 2))

It should be written as (s missing)

Also, the codes in the Golvin Hacker - TensorFlow book seem to be all in golbin/TensorFlow-Tutorials.

You'd better refer to this!


2022-09-21 15:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.