zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject zeppelin git commit: [ZEPPELIN-1327] Fix bug in z.show for Python interpreter
Date Fri, 26 Aug 2016 01:19:35 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master 42e3a141d -> 8064c5491


[ZEPPELIN-1327] Fix bug in z.show for Python interpreter

### What is this PR for?
Currently, height parameter for z.show implementation to display PNG images in Python interpreter
is not working. This PR fix that bug.

### What type of PR is it?
Bug Fix

### What is the Jira issue?
[ZEPPELIN-1327](https://issues.apache.org/jira/browse/ZEPPELIN-1327)

### How should this be tested?
```python
import matplotlib.pyplot as plt

x = [1,2,3,4,5]
y = [6,7,8,9,0]

plt.plot(x, y, marker="o")
z.show(plt, height="200px")
plt.close()
```

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Paul Bustios <pbustios@gmail.com>

Closes #1352 from bustios/ZEPPELIN-1327 and squashes the following commits:

8eff11a [Paul Bustios] Change default values of width and height and add img tag for PNG images
b3c74a8 [Paul Bustios] Add comment explaining the need for decoding bytes to string
1a78a37 [Paul Bustios] Fix bug in z.show for Python interpreter


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/8064c549
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/8064c549
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/8064c549

Branch: refs/heads/master
Commit: 8064c54917f86ad08a15ba8c86341dce6dfac391
Parents: 42e3a14
Author: Paul Bustios <pbustios@gmail.com>
Authored: Tue Aug 23 17:54:07 2016 -0300
Committer: Alexander Bezzubov <bzz@apache.org>
Committed: Fri Aug 26 10:19:30 2016 +0900

----------------------------------------------------------------------
 python/src/main/resources/bootstrap.py | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/8064c549/python/src/main/resources/bootstrap.py
----------------------------------------------------------------------
diff --git a/python/src/main/resources/bootstrap.py b/python/src/main/resources/bootstrap.py
index 16950fd..235f7ab 100644
--- a/python/src/main/resources/bootstrap.py
+++ b/python/src/main/resources/bootstrap.py
@@ -117,7 +117,6 @@ class PyZeppelinContext(object):
     
     def __init__(self):
         self.max_result = 1000
-        self.py3 = bool(sys.version_info >= (3,))
     
     def input(self, name, defaultValue=""):
         print(self.errorMsg)
@@ -165,28 +164,27 @@ class PyZeppelinContext(object):
         #)
         body_buf.close(); header_buf.close()
     
-    def show_matplotlib(self, p, width="100%", height="100%",
-                        fmt='png', **kwargs):
+    def show_matplotlib(self, p, fmt="png", width="auto", height="auto", 
+                        **kwargs):
         """Matplotlib show function
         """
-        if fmt == 'png':
+        if fmt == "png":
             img = BytesIO()
             p.savefig(img, format=fmt)
-            html = "%html <img src={img} width={width}, height={height}>"
             img_str = b"data:image/png;base64,"
             img_str += base64.b64encode(img.getvalue().strip())
-            # Need to do this for python3 compatibility
-            if self.py3:
-                img_str = img_str.decode('ascii')
-                
-        elif fmt == 'svg':
+            img_tag = "<img src={img} style='width={width};height:{height}'>"
+            # Decoding is necessary for Python 3 compability
+            img_str = img_str.decode("ascii")
+            img_str = img_tag.format(img=img_str, width=width, height=height)
+        elif fmt == "svg":
             img = StringIO()
             p.savefig(img, format=fmt)
-            html = "%html <div style='width:{width};height:{height}'>{img}<div>"
             img_str = img.getvalue()
         else:
             raise ValueError("fmt must be 'png' or 'svg'")
         
+        html = "%html <div style='width:{width};height:{height}'>{img}<div>"
         print(html.format(width=width, height=height, img=img_str))
         img.close()
 


Mime
View raw message