plotly.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:lddmm-ot 作者: jeanfeydy 项目源码 文件源码
def save_as(cls, figure_or_data, filename, format=None, width=None,
                height=None, scale=None):
        """Save a image of the plot described by `figure_or_data` locally as
        `filename`.

        Valid image formats are 'png', 'svg', 'jpeg', and 'pdf'.
        The format is taken as the extension of the filename or as the
        supplied format.

        positional arguments:
        - figure_or_data: The figure dict-like or data list-like object that
                          describes a plotly figure.
                          Same argument used in `py.plot`, `py.iplot`,
                          see https://plot.ly/python for examples
        - filename: The filepath to save the image to
        - format: 'png', 'svg', 'jpeg', 'pdf'
        - width: output width
        - height: output height
        - scale: Increase the resolution of the image by `scale` amount
               Only valid for PNG and JPEG images.

        example:
import plotly.plotly as py
    fig = {'data': [{'x': [1, 2, 3], 'y': [3, 1, 5], 'type': 'bar'}]}
    py.image.save_as(fig, 'my_image.png', scale=3)
    ```
    """
    # todo: format shadows built-in name
    (base, ext) = os.path.splitext(filename)
    if not ext and not format:
        filename += '.png'
    elif ext and not format:
        format = ext[1:]
    elif not ext and format:
        filename += '.' + format

    img = cls.get(figure_or_data, format, width, height, scale)

    f = open(filename, 'wb')
    f.write(img)
    f.close()

```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号