Repository: zeppelin
Updated Branches:
  refs/heads/master 6b6f1cb76 -> 9eac20d08


[ZEPPELIN-1261] Bug fix in z.show() for matplotlib graphs

### What is this PR for?
Bug fix in z.show() for matplotlib graphs and code refactoring

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

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

### 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="20em")
plt.close()
```
```
%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="300px")
plt.close()
```

### Screenshots (if appropriate)
![plot](https://dl.dropboxusercontent.com/u/20947972/z.show.height.example.png)

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

Author: Paul Bustios <[email protected]>

Closes #1267 from bustios/ZEPPELIN-1261 and squashes the following commits:

82c631a [Paul Bustios] Add 100% as a default value for width and height 
z.show() parameters
3e0ef22 [Paul Bustios] Bug fix in show_matplotlib


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

Branch: refs/heads/master
Commit: 9eac20d08a2905af178173ccb3aa5cc105f11bc5
Parents: 6b6f1cb
Author: Paul Bustios <[email protected]>
Authored: Tue Aug 2 18:35:53 2016 -0300
Committer: Alexander Bezzubov <[email protected]>
Committed: Wed Aug 3 13:52:04 2016 +0900

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


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9eac20d0/python/src/main/resources/bootstrap.py
----------------------------------------------------------------------
diff --git a/python/src/main/resources/bootstrap.py 
b/python/src/main/resources/bootstrap.py
index 638ef9b..0290c5f 100644
--- a/python/src/main/resources/bootstrap.py
+++ b/python/src/main/resources/bootstrap.py
@@ -162,20 +162,13 @@ class PyZeppelinContext(object):
         #)
         body_buf.close(); header_buf.close()
     
-    def show_matplotlib(self, p, width="0", height="0", **kwargs):
+    def show_matplotlib(self, p, width="100%", height="100%", **kwargs):
         """Matplotlib show function
         """
         img = io.StringIO()
-        p.savefig(img, format='svg')
-        img.seek(0)
-        style = ""
-        if (width != "0"):
-            style += 'width:' + width
-        if (height != "0"):
-            if (len(style) != 0):
-                style += ","
-                style += 'height:' + height
-        print("%html <div style='" + style + "'>" + img.read() + "<div>")
+        p.savefig(img, format="svg")
+        html = "%html <div style='width:{width};height:{height}'>{image}<div>"
+        print(html.format(width=width, height=height, image=img.getvalue()))
         img.close()
 
 

Reply via email to