@@ -545,7 +545,7 @@ class image:
545
545
546
546
"""
547
547
@staticmethod
548
- def get (figure_or_data , format = 'png' , width = None , height = None ):
548
+ def get (figure_or_data , format = 'png' , width = None , height = None , scale = None ):
549
549
"""
550
550
Return a static image of the plot described by `figure`.
551
551
@@ -570,6 +570,13 @@ def get(figure_or_data, format='png', width=None, height=None):
570
570
"supported file types here: "
571
571
"https://plot.ly/python/static-image-export/"
572
572
)
573
+ if scale is not None :
574
+ try :
575
+ scale = float (scale )
576
+ except :
577
+ raise exceptions .PlotlyError (
578
+ "Invalid scale parameter. Scale must be a number."
579
+ )
573
580
574
581
headers = _api_v2 .headers ()
575
582
headers ['plotly_version' ] = version .__version__
@@ -580,7 +587,8 @@ def get(figure_or_data, format='png', width=None, height=None):
580
587
payload ['width' ] = width
581
588
if height is not None :
582
589
payload ['height' ] = height
583
-
590
+ if scale is not None :
591
+ payload ['scale' ] = scale
584
592
url = _api_v2 .api_url ('images/' )
585
593
586
594
res = requests .post (
@@ -614,21 +622,22 @@ def get(figure_or_data, format='png', width=None, height=None):
614
622
"not be translated." )
615
623
raise exceptions .PlotlyError (return_data ['error' ])
616
624
617
-
618
625
@classmethod
619
- def ishow (cls , figure_or_data , format = 'png' , width = None , height = None ):
626
+ def ishow (cls , figure_or_data , format = 'png' , width = None , height = None ,
627
+ scale = None ):
620
628
"""
621
629
Display a static image of the plot described by `figure`
622
630
in an IPython Notebook.
623
631
624
632
"""
625
633
if format == 'pdf' :
626
- raise exceptions .PlotlyError ("Aw, snap! "
634
+ raise exceptions .PlotlyError (
635
+ "Aw, snap! "
627
636
"It's not currently possible to embed a pdf into "
628
637
"an IPython notebook. You can save the pdf "
629
638
"with the `image.save_as` or you can "
630
639
"embed an png, jpeg, or svg." )
631
- img = cls .get (figure_or_data , format , width , height )
640
+ img = cls .get (figure_or_data , format , width , height , scale )
632
641
from IPython .display import display , Image , SVG
633
642
if format == 'svg' :
634
643
display (SVG (img ))
@@ -637,7 +646,7 @@ def ishow(cls, figure_or_data, format='png', width=None, height=None):
637
646
638
647
@classmethod
639
648
def save_as (cls , figure_or_data , filename , format = None , width = None ,
640
- height = None ):
649
+ height = None , scale = None ):
641
650
"""
642
651
Save a image of the plot described by `figure` locally as `filename`.
643
652
@@ -655,7 +664,7 @@ def save_as(cls, figure_or_data, filename, format=None, width=None,
655
664
elif not ext and format :
656
665
filename += '.' + format
657
666
658
- img = cls .get (figure_or_data , format , width , height )
667
+ img = cls .get (figure_or_data , format , width , height , scale )
659
668
660
669
f = open (filename , 'wb' )
661
670
f .write (img )
0 commit comments