import logging

import numpy as np
from matplotlib import pyplot as plt
from roipoly import Roipoly


logger = logging.getLogger(__name__)

logging.basicConfig(format='%(levelname)s ''%(processName)-10s : %(asctime)s %(module)'
                            's.%(funcName)s:%(lineno)s %(message)s',
                    level=logging.DEBUG)

# create image
img = np.ones((100, 100)) * range(0, 100)

# show the image
plt.imshow(img, interpolation='nearest', cmap="Greys")
plt.colorbar()
plt.title("left click: line segment         right click: close region")

# let user draw first ROI
roi1 = Roipoly(roicolor='r') #let user draw first ROI

# show the image with the first ROI
plt.imshow(img, interpolation='nearest', cmap="Greys")
plt.colorbar()
roi1.display_roi()
plt.title('draw second ROI')

# let user draw second ROI
roi2 = Roipoly(roicolor='b') #let user draw ROI

# show the image with both ROIs and their mean values
plt.imshow(img, interpolation='nearest', cmap="Greys")
plt.colorbar()
[x.display_roi() for x in [roi1, roi2]]
[x.display_mean(img) for x in [roi1, roi2]]
plt.title('The two ROIs')
plt.show()

# show ROI masks
plt.imshow(roi1.get_mask(img) + roi2.get_mask(img),
          interpolation='nearest', cmap="Greys")
plt.title('ROI masks of the two ROIs')
plt.show()



@@ -65,16 +65,17 @@
  as plt%0A
+%0A
 from roi
@@ -93,15 +93,14 @@
  Roi
-p
+P
 oly%0A%0A
-%0A
 logg
@@ -214,17 +214,8 @@
 e)s 
-%25(module)
 '%0A  
@@ -239,18 +239,26 @@
         
- 
 '
+%25(module)
 s.%25(func
@@ -333,17 +333,17 @@
 BUG)%0A%0A# 
-c
+C
 reate im
@@ -387,25 +387,25 @@
 (0, 100)%0A%0A# 
-s
+S
 how the imag
@@ -406,16 +406,35 @@
 e image%0A
+fig = plt.figure()%0A
 plt.imsh
@@ -566,21 +566,43 @@
 region%22)
+%0Aplt.show(block=False)
 %0A%0A# 
-l
+L
 et user 
@@ -622,32 +622,29 @@
 I%0Aroi1 = Roi
-p
+P
 oly(
-roi
 color='r') #
@@ -644,39 +644,23 @@
 ='r'
-) #let user draw first ROI
+, fig=fig)
 %0A%0A# 
-s
+S
 how 
@@ -688,16 +688,35 @@
 rst ROI%0A
+fig = plt.figure()%0A
 plt.imsh
@@ -828,13 +828,35 @@
 OI')
+%0Aplt.show(block=False)
 %0A%0A# 
-l
+L
 et u
@@ -889,16 +889,13 @@
  Roi
-p
+P
 oly(
-roi
 colo
@@ -903,33 +903,23 @@
 ='b'
-) #let user draw ROI
+, fig=fig)
 %0A%0A# 
-s
+S
 how 
@@ -1159,17 +1159,17 @@
 ow()%0A%0A# 
-s
+S
 how ROI 
@@ -1236,16 +1236,17 @@
         
+ 
 interpol
@@ -1326,10 +1326,8 @@
 .show()%0A
-%0A%0A

update example