1

I have to visualize preliminary processing results, that only exist as numpy ndarrays. To do so, I am using pyplot (plt) from matplotlib and imshow + subplots.

fig, ((mb_arr, mk_arr),(k10_b, k10_l)) = plt.subplots(3, 2, figsize=(16, 12))
mb_arr.imshow(mb_2014_array, cmap='gray', interpolation='nearest')
mk_arr.imshow(mk_2014_array, cmap='gray', interpolation='nearest')
k10_b.imshow(k10_build_array, cmap='gray', interpolation='nearest')
k10_l.imshow(k10_lake_array, cmap='gray', interpolation='nearest')
k10_f.imshow(k10_forest_array, cmap='gray', interpolation='nearest');

However, I am stuck with four out of five results, because I can't get the fifth array printed in the setup of subplots. Below is the code I am using at the moment, and the error here is:

--> fig, ((mb_arr, mk_arr),(k10_b, k10_l), (k10_f, )) = plt.subplots(3, 2, figsize=(16, 12))

ValueError: too many values to unpack

How do I have to specify, that the last row in the 3 x 2 grid will contain only one element?

1 Answer 1

1

I used http://www.python-course.eu/matplotlib_multiple_figures.php

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 1000)
plt.figure()
for i in range(1, 5):
    plt.subplot(3,2,i)
    plt.plot(np.sin(x))
plt.subplot(3,2,(5,6))
plt.plot(np.sin(x))
plt.show()

and with imshow and cmap and interpolation.

import matplotlib.pyplot as plt
import numpy as np
np.random.seed(2)
x = np.random.randint(0, 255, [10, 20])
fig = plt.figure()
for i in range(1, 5):
    plt.subplot(3,2,i)
    plt.imshow(x, cmap='gray', interpolation='nearest')
plt.subplot(3,2,(5,6))
plt.imshow(x, cmap='gray', interpolation='nearest')
plt.show()
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I've seen the course and the examples as well. Using subplot I can arrange the different arrays. Any chance for a solution using the subplots method?
Sorry I realized that too late. Your solution works for sure. Would you know how to get it to work with subplots?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.