Browse Source

保存图片

张世豪 3 months ago
parent
commit
41a74a7313
2 changed files with 13 additions and 1 deletions
  1. 6 0
      .idea/vcs.xml
  2. 7 1
      report.py

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 7 - 1
report.py

@@ -122,7 +122,13 @@ def getInteractiveImg(x,y,label,x1,y1,label1,x2,y2,label2,url,name,xLabel,YLabel
     html_file_path = f"{url}/{name}.html"
     pio.write_html(fig, file=html_file_path, auto_open=False)
     # 同时保存一份图片
-    pio.write_image(fig, f"{url}/{name}.png")
+    try:
+        print(pio.kaleido.scope.plotlyjs)
+        print(f"图片将保存至 " + f"{url}/{name}.png")
+        fig.write_image(f"{url}/{name}.png",scale=3, width=800, height=600)
+        print(f"图片已成功保存至 "+f"{url}/{name}.png")
+    except Exception as e:
+        print(f"保存图片时出现错误: {str(e)}")
     # 在文档中中插入html
     # workbook = load_workbook(filename=fileUrl)
     # # 选择一个工作表