Repository: scikit-image/scikit-image

Issue:
Bug: io.imshow() and io.show() do not work as expected in winows
In my win7-x64 environemnt, io.imshow() and io.show() do not work as expected. I use  io.imshow() to show mutiple images, and when I call io.show() to show all the images, only the last image shows. In linux, it works well and all the images will show when I call io.show()



Discussion:
Would you mind telling us how you installed Python? There are a lot of different packages/binaries/etc. available for Windows, and to track this down that would be very helpful.

Also, are any errors or warnings printed? Are dummy/empty windows generated, or just one for the final image?

The version I installed is 3.3.2 from the python official websites, and all the other packages are installed stand alone by downloading binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/. No any messages(errors/warnings) are printed, and no dummy/empty windows generated, just the last one there. It's not the problem of python version, because on my archlinux, the version of python is also 3.3.2

It depends on which plugin is picked up by the system.  To be safe, add

```
from skimage import io
io.use_plugin('matplotlib')
```

to the top of your script.  I may even recommend simply using matplotlib to visualize output anyway.

I have already used that method, force using 'matplotlib' as the backend. But it still doesn't work...

What does the following do?

```
import matplotlib.pyplot as plt
f1 = plt.figure()
plt.plot([1,2,3])
f2 = plt.figure()
plt.plot([4,5,6])
plt.show()
```

The code above do the right thing, two figures are showed

This might rather be a bug on the other platform.  Matplotlib is not supposed to pop up multiple windows for successive imshows.  E.g., you can probably get the behaviour you want with:

```
plt.figure()
io.imshow(x)

plt.figure()
io.imshow(y)

io.show()
```

This may be a a solution, but still not elegant, anyhow, thank you very much.

@TiancaiYe `io.imshow` is only aimed at visualizing a single image at a time.  If you want anything more involved, you should use either matplotlib directly, or the `skimage.viewer` tools.

Hrm, then again, why shouldn't we make it create a new figure every time.  @TiancaiYe I think this would simply require a "plt.figure()" call at the beginning of each imshow.  What do you think @JDWarner ?

This is a good idea, the only thing need to care about is that we need to check which backend is using. If the backend is matplotlib, then call 'plt.figure()' at the beginning of 'imshow()'

@TiancaiYe It's even easier: we just update `pil_plugin.py` to do so inside `imshow`.  It's a one-line fix, if you want to submit a PR.  Look under `skimage/io/_plugins`.

@stefanv Yup, sounds like a good one-liner!

Should we try and detect if the current figure has content?  That way if they created a blank figure we'd use that:

``` python
if plt.gca().has_data():
   plt.figure()
```


Resolving patch:
diff --git a/skimage/io/_plugins/matplotlib_plugin.py b/skimage/io/_plugins/matplotlib_plugin.py
--- a/skimage/io/_plugins/matplotlib_plugin.py
+++ b/skimage/io/_plugins/matplotlib_plugin.py
@@ -2,6 +2,8 @@
 
 
 def imshow(*args, **kwargs):
+    if plt.gca().has_data():
+        plt.figure()
     kwargs.setdefault('interpolation', 'nearest')
     kwargs.setdefault('cmap', 'gray')
     plt.imshow(*args, **kwargs)


Test patch: