@@ -358,8 +358,12 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
358
358
plot_html , plotdivid , width , height = _plot_html (
359
359
figure_or_data , config , validate , '100%' , 525 , True
360
360
)
361
- display_bundle ['text/html' ] = plot_html
362
- display_bundle ['text/vnd.plotly.v1+html' ] = plot_html
361
+ resize_script = ''
362
+ if width == '100%' or height == '100%' :
363
+ resize_script = _build_resize_script (plotdivid )
364
+
365
+ display_bundle ['text/html' ] = plot_html + resize_script
366
+ display_bundle ['text/vnd.plotly.v1+html' ] = plot_html + resize_script
363
367
364
368
ipython_display .display (display_bundle , raw = True )
365
369
@@ -389,6 +393,17 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
389
393
ipython_display .display (ipython_display .HTML (script ))
390
394
391
395
396
+ def _build_resize_script (plotdivid ):
397
+ resize_script = (
398
+ ''
399
+ '<script type="text/javascript">'
400
+ 'window.addEventListener("resize", function(){{'
401
+ 'Plotly.Plots.resize(document.getElementById("{id}"));}});'
402
+ '</script>'
403
+ ).format (id = plotdivid )
404
+ return resize_script
405
+
406
+
392
407
def plot (figure_or_data , show_link = True , link_text = 'Export to plot.ly' ,
393
408
validate = True , output_type = 'file' , include_plotlyjs = True ,
394
409
filename = 'temp-plot.html' , auto_open = True , image = None ,
@@ -477,13 +492,7 @@ def plot(figure_or_data, show_link=True, link_text='Export to plot.ly',
477
492
478
493
resize_script = ''
479
494
if width == '100%' or height == '100%' :
480
- resize_script = (
481
- ''
482
- '<script type="text/javascript">'
483
- 'window.addEventListener("resize", function(){{'
484
- 'Plotly.Plots.resize(document.getElementById("{id}"));}});'
485
- '</script>'
486
- ).format (id = plotdivid )
495
+ resize_script = _build_resize_script (plotdivid )
487
496
488
497
if output_type == 'file' :
489
498
with open (filename , 'w' ) as f :
0 commit comments