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,latexA 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 = True404 : Not Found 然而導出還是報上面的錯
尚待解決,目前使用只能使用截屏SVG圖,保存為png后使用
Markdown cell 里包含圖片(svgpng)
使用markdown方法
- 使用![]()的方法添加圖片,——MARKDOWN寫法,在導出為markdown時,其文件夾含圖片(Png,svg均可正確導出),但是魔法函數,及markdown方法,需要手工置換一下圖片(使用新生成的圖片名)
- 在單元格里使用魔法函數的方法或markdown圖片方法后,轉為HTML,直接使用jupyter文件打印,不能正確顯示。說明這兩種方法都未產生PostScript格式的輸出。(應用程序jupyter的notebook未提供此功能,但在windonws里一些專業的MARKDOWN程序可以) 寫法為:;
效果如下圖:
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
一個重點問題,在notebook文件里使用SVG圖片需要注意的
- 要得到大小合適得SVG圖,在drawio里畫時需要留意其適合頁面得大小,一旦存檔為svg,在此無法更改顯示大小
- Notebook默認以嵌入方式加載圖片,以便文件拷貝到其他地方,或OFFlINE時可以使用,但是一旦再次運行本單元格,則會報錯,如果所需文件,因為引用的圖片文件可能不在路徑上
- 下圖,是在插件drawio里按A4頁面大小畫好的,放入這里后,轉HTML,按A4打印,可完美的顯示
- 使用IPython.display的HTML 類,可以展示SVG圖,但是不能在轉出的HTML里正確顯示,也就不能打印
總結
以上是生活随笔為你收集整理的html转图片_jupyter lab 笔记添加图片的方法汇总的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 4路组相连cache设计_移动图形处理器
- 下一篇: python 柱状图宽度设置_Pytho