日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html转图片_jupyter lab 笔记添加图片的方法汇总

發布時間:2025/4/5 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html转图片_jupyter lab 笔记添加图片的方法汇总 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如何使用ipython筆記本——添加豐富的內容(圖片部分)

IPython's Rich Display System In Python, objects can declare their textual representation using the __repr__ method. IPython expands on this idea and allows objects to declare other, richer representations including: html,json,png,svg,latex
A single object can declare some or all of these representations; all are handled by IPython's display system
更多詳情了解,到鏈接網頁下,Part 5 查看Ipthon rich display system

用插件Drawio,畫流程圖后只能保存為svg圖

Drawio插件安裝記錄

$jupyter labextension install jupyterlab-drawio

查看插件是否安裝成功

$ jupyter labextension list

troubleshooting ‘_xsrf’ argument missing from POST畫好后,將結果導出為圖片,報上面錯誤

在juypter_notebook_config.py中修改配置

#c.NotebookApp.disable_check_xsrf = Falsec.NotebookApp.disable_check_xsrf = True

404 : Not Found 然而導出還是報上面的錯

尚待解決,目前使用只能使用截屏SVG圖,保存為png后使用

Markdown cell 里包含圖片(svgpng)

使用markdown方法

  • 使用![]()的方法添加圖片,——MARKDOWN寫法,在導出為markdown時,其文件夾含圖片(Png,svg均可正確導出),但是魔法函數,及markdown方法,需要手工置換一下圖片(使用新生成的圖片名)
  • 在單元格里使用魔法函數的方法或markdown圖片方法后,轉為HTML,直接使用jupyter文件打印,不能正確顯示。說明這兩種方法都未產生PostScript格式的輸出。(應用程序jupyter的notebook未提供此功能,但在windonws里一些專業的MARKDOWN程序可以) 寫法為:![樣圖](pic/g3344.png);

效果如下圖:

nas

使用ipython rich display system

1.Basic display import, The display function is a general purpose tool for displaying different representations of objects. Think of it as print for these rich representations.

from IPython.display import SVG #或1)from IPython.display import display_svg,SVG #或2)from IPython.display import display,SVG SVG(filename='pic/sample.svg') #或1)display_svg(SVG(filename="sample.svg")) #或2)display(SVG(filename="sample.svg"))

2.使用IPython模塊display函數Image類,添加圖片

from IPython.display import Image Image(filename='pic/sample.png',width=800,height=800)

3.使用IPython模塊display函數SVG類,添加圖片,適合轉為HTML,再打印

from IPython.display import SVG SVG(filename='pic/sample.svg')

4.更多詳細如下:

from IPython.display import display

  • Calling display on an object will send all possible representations to the Notebook.
  • These representations are stored in the Notebook document.
  • In general the Notebook will use the richest available representation.

from IPython.display import display_pretty, display_html, display_jpeg, display_png, display_json, display_latex, display_svg

  • If you want to display a particular representation, there are specific functions for that

from IPython.display import Image

  • To work with images (JPEG, PNG) use the Image class.
  • 用法,例:i = Image(filename='logo/logo.png') ,然后調用i 或,display(i)
  • An image can also be displayed from raw data or a url,例:Image(url='http://python.org/images/python-logo.gif')

使用魔法函數

  • 可以在Jupyter里顯示,但轉為HTML看不到圖片,看來魔法函數僅適合只在notebook里用,不適合打印或轉HTML
%%html <img src="pic/sample.png" width=500 height=300></img>

一個重點問題,在notebook文件里使用SVG圖片需要注意的

  • 要得到大小合適得SVG圖,在drawio里畫時需要留意其適合頁面得大小,一旦存檔為svg,在此無法更改顯示大小
  • Notebook默認以嵌入方式加載圖片,以便文件拷貝到其他地方,或OFFlINE時可以使用,但是一旦再次運行本單元格,則會報錯,如果所需文件,因為引用的圖片文件可能不在路徑上
  • 下圖,是在插件drawio里按A4頁面大小畫好的,放入這里后,轉HTML,按A4打印,可完美的顯示
  • 使用IPython.display的HTML 類,可以展示SVG圖,但是不能在轉出的HTML里正確顯示,也就不能打印
from IPython.display import SVG svgfig = SVG(filename="pic/untitled.svg") #調用該實例 svgfig #或使用display() display(svgfig)

總結

以上是生活随笔為你收集整理的html转图片_jupyter lab 笔记添加图片的方法汇总的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。