mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Change default values of width and height and add img tag for PNG images
This commit is contained in:
parent
b3c74a8883
commit
8eff11af9a
1 changed files with 4 additions and 3 deletions
|
|
@ -164,7 +164,7 @@ class PyZeppelinContext(object):
|
|||
#)
|
||||
body_buf.close(); header_buf.close()
|
||||
|
||||
def show_matplotlib(self, p, fmt="png", width="100%", height="100%",
|
||||
def show_matplotlib(self, p, fmt="png", width="auto", height="auto",
|
||||
**kwargs):
|
||||
"""Matplotlib show function
|
||||
"""
|
||||
|
|
@ -173,9 +173,10 @@ class PyZeppelinContext(object):
|
|||
p.savefig(img, format=fmt)
|
||||
img_str = b"data:image/png;base64,"
|
||||
img_str += base64.b64encode(img.getvalue().strip())
|
||||
# Decoding img_str is necessary for Python 3 compability
|
||||
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 src={img}>".format(img=img_str)
|
||||
img_str = img_tag.format(img=img_str, width=width, height=height)
|
||||
elif fmt == "svg":
|
||||
img = StringIO()
|
||||
p.savefig(img, format=fmt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue