Matplotlib produces a black image from an array full of ones
<p><strong>Intro</strong></p>

<p>I am doing some tests with <code>matplotlib.pyplot</code>. When I tried to save artificial images, I encoutered a strange behavior. Here is the very simple function I created to save images : </p>

<pre><code>import numpy as np
import matplotlib
import matplotlib.pyplot as plt

def save_image(array, name):

    array = array*255.
    fig = plt.figure()
    plt.imsave(name, array.astype('uint8'), cmap=matplotlib.cm.gray)
    plt.close(fig)

return 0
</code></pre>

<p><strong>The problem</strong></p>

<p>When I try to create an image with an array full of zeros, I get a dark image, as expected :</p>

<pre><code>zeros_array = np.zeros((200,200), dtype='float')
save_image(zeros_array, 'Dark.jpg')
</code></pre>

<p><a href="https://i.stack.imgur.com/DwDdA.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/DwDdA.jpg" alt="Dark.jpg"></a></p>

<p>However, when I try to create an image with an array full of ones, I still get a dark image :</p>

<pre><code>ones_array = np.ones((200,200), dtype='float')
save_image(ones_array, 'White.jpg')
</code></pre>

<p><a href="https://i.stack.imgur.com/CICX1.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/CICX1.jpg" alt="White.jpg"></a></p>

<p>Interestingly enough, when I create a <code>mixed_array</code>, with squares of different intensities, the regions full of ones now appear as white :</p>

<pre><code>mixed_array = np.ones((200,200), dtype='float')
mixed_array[:100,:100] = 0.25
mixed_array[100:,100:] = 0.75
save_image(mixed_array, 'Mixed.jpg')
</code></pre>

<p><a href="https://i.stack.imgur.com/THcB9.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/THcB9.jpg" alt="Mixed.jpg"></a></p>

<p><strong>Question :</strong> </p>

<p>Does anyone know why <code>matplotlib</code> refuses to save a full white image but has no problem with white regions in an image?</p>

<p>I am probably missing something very obvious or fundamental but I cannot see what.</p>