python - 如何打开扩展名为 ".plotly"的文件

标签 python plotly

我下载了一个我在 Copernicus website 的交互式工具箱上创建的文件关于气候。

我保存了这个扩展名:".plotly"

如何打开它 - 以便我可以将其作为图片查看?

这是文件的内容:

{"data": [{"mode": "lines+markers", "x": ["2019-01-01", "2019-01-02", "2019-01-03", "2019-01-04", "2019-01-05", "2019-01-06", "2019-01-07", "2019-01-08", "2019-01-09", "2019-01-10", "2019-01-11", "2019-01-12", "2019-01-13", "2019-01-14", "2019-01-15", "2019-01-16", "2019-01-17", "2019-01-18", "2019-01-19", "2019-01-20", "2019-01-21", "2019-01-22", "2019-01-23", "2019-01-24", "2019-01-25", "2019-01-26", "2019-01-27", "2019-01-28", "2019-01-29", "2019-01-30", "2019-01-31"], "y": [1.986506462097168, 1.139273762702942, -0.1418689787387848, -0.714171290397644, -0.4602118134498596, -0.2752906382083893, -0.5288987755775452, -0.7405713796615601, -0.7374019622802734, -0.5999566912651062, -0.5094485878944397, 0.10179024189710617, 1.217246174812317, 1.4535152912139893, 0.9326292872428894, 0.5662962198257446, 0.9379780888557434, 0.3954199254512787, -0.06783988326787949, -0.23851798474788666, -0.8703995943069458, -1.6232084035873413, -0.9794990420341492, -0.9441877007484436, -0.7926209568977356, -0.014816214330494404, -0.14320173859596252, -0.06497668474912643, 0.49699893593788147, 0.4733152687549591, 0.7467145919799805], "type": "scatter", "uid": "ceb1c461-59bb-48e9-bfcc-63396d23a3c9"}], "layout": {"yaxis": {"title": {"text": "Near-Surface Air Temperature anomaly (K)"}}, "xaxis": {"title": {"text": "time"}}}}

最佳答案

您的文件是 Plotly JSON chart schema并且可以翻译成多种不同的语言,包括 python :

Translations of the JSON schema for practical use in several languages are also available:

Python: https://plot.ly/python/reference/
R: https://plot.ly/r/reference/
MATLAB: https://plot.ly/matlab/reference/
JavaScript: https://plot.ly/javascript/reference/


直接回答您的问题,您可以使用 Plotly JSON chart schema (json) python 文件如下:

import plotly.graph_objects as go
import json

with open("filename.plotly") as f:
    config = json.load(f)

fig = go.Figure(data=config['data'], layout=config['layout'])
fig.show()

enter image description here

关于python - 如何打开扩展名为 ".plotly"的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61397676/

相关文章:

python - 如何获得今天的开始时间?

python - 使用 zipfile python 模块创建完整目录的 zip

python - 更改 Plotly TreeMap 中边框的宽度

r - 如何防止x轴与facet_wrap(~variable)重叠ggplotly

python - 随着时间的推移增加 python 进程内存

python - Keras 中的输入和输出维度错误

python - 如何避免使用过多的 if else ?

r - 在 Rmarkdown(knitr chunk)文档中生成的多个(R)绘图图形

r - 在单个3D图中混合表面和散点图

python - Plotly 3D 绘图注释