jupyter 插入本地图片
时间: 2024-03-28 11:34:56 浏览: 420
在Jupyter Notebook中插入本地图片可以通过以下步骤完成:
1. 首先,将图片文件保存在Jupyter Notebook所在的目录或子目录中。
2. 在Jupyter Notebook中使用Markdown单元格,通过以下语法插入图片:
```

```
其中,图片描述是可选的,可以用于给图片添加说明;图片路径是相对于Jupyter Notebook文件的路径。
3. 运行Markdown单元格,即可在Notebook中显示插入的图片。
请注意,如果图片路径包含中文或特殊字符,建议将其改为英文或使用URL编码。另外,确保图片文件格式正确,并且Jupyter Notebook所在的目录具有读取图片文件的权限。
相关问题
如何Jupyter插入本地图片
### 如何在Jupyter Notebook中插入本地图片
在Jupyter Notebook环境中,有多种方式可以插入本地图片。一种常见的方式是利用Markdown语法结合HTML标签实现图像显示。
对于希望保持项目结构整洁的情况,可以选择使用相对路径指向存储于同一仓库下的图片资源:
```markdown
[^1]
```
上述代码片段展示了通过指定相对于Notebook文件位置的本地URL加载图片的方法。
另一种更为直接但可能导致.ipynb文件显著增大的方案,则是采用`IPython.display.Image`类配合base64编码将图片嵌入到笔记本文档内部:
```python
from IPython.display import Image
with open("./path/to/local/image.jpg", "rb") as f:
display(Image(data=f.read(), format='jpg', embed=True))
```
这种方式会把图片转换成字符串形式保存至Notebook之中,使得分享时不依赖外部链接即可查看图片内容。
jupyter 插入图片
要在Jupyter Notebook中插入图片,你可以使用HTML标签`<img>`或者Markdown的图片语法`![]()`。对于HTML标签方式,你可以使用以下代码插入网络图片:
```python
<img src="http://jupyter.org/assets/main-logo.svg" width=320 height=240>
```
这将插入一张宽度为320像素,高度为240像素的网络图片。
另外,你也可以使用Markdown语法来插入网络图片:
```python

```
这将插入一张名为`jupyter`的网络图片。
如果你要插入本地图片,你需要将图片源更改为图片的本地路径,可以是绝对路径或相对路径。例如:
```python

```
这将插入一张名为`jupyter`的本地图片。
阅读全文
相关推荐














