我正在尝试保存我在 R 的 Synapse Analytics 笔记本中创建的
ggplot
。
我发现了一个上一个问题解释了如何在 Python 中执行操作,但我无法在 R 中复制它们。
我使用
mssparkutils.fs.mount()
成功安装了 Azure Blob 存储帐户,并且能够使用 mssparkutils.fs.ls()
查看该帐户。但是,当我尝试使用 ggsave()
将绘图保存到 file:/{mount_path}/local/...
时,我在指定路径中看不到该文件。
在笔记本本身中,我只看到一条消息“在图像中保存 6.67 x 6.67”。
我对此有点陌生,所以如果我使用了错误的术语,请道歉。
我在
matplotlib
中尝试了以下方法来绘制和保存图像:
mssparkutils.fs.mount(
"abfss://[email protected]",
"/mnt",
{ "linkedService": "synpsilip-WorkspaceDefaultStorage" }
)
mssparkutils.fs.mkdirs("/mnt/folder02")
local_plot_path = "/tmp/sample_plot.png"
plt.savefig(local_plot_path)
print(f"Plot saved locally at: {local_plot_path}")
dest_plot_path = "/mnt/folder02/sample_plot.png"
mssparkutils.fs.cp(f"file://{local_plot_path}", f"abfss://[email protected]/folder02/sample_plot.png")
print(f"Plot copied to: {dest_plot_path} in Blob Storage")
files = mssparkutils.fs.ls("/mnt/folder02")
for file in files:
print(file.name)
在上面的代码中安装Azure Blob存储并创建目录 在本地保存绘图并将文件复制到挂载的 Azure Blob 存储目录中的列表文件进行验证
结果:
/mnt
Plot saved locally at: /tmp/sample_plot.png
Plot copied to: /mnt/folder02/sample_plot.png in Blob Storage