display image jupyter notebook aligned centre

◇◆丶佛笑我妖孽 提交于 2021-02-07 12:23:30

问题


I am using the following code to insert an image in Jupyter notebook which is compatible with html conversion:

from IPython.display import Image

Image(filename="picture.jpg")

This works nicely except the fact that it is left aligned and I need it centre/middle aligned. Is there any method that I can set it to be aligned correctly?


回答1:


You can set the cell as markdown and use this content:

<img src="picture.jpg" width="240" height="240" align="center"/>

Then run it.

Edit1

Alternatively, you can use a code cell with this code:

from IPython.display import HTML
html1 = '<img src="picture.jpg" width="240" height="240" align="center"/>'
HTML(html1)



回答2:


This works for me:

<center><img src="picture.jpg"/></center>


来源:https://stackoverflow.com/questions/46439874/display-image-jupyter-notebook-aligned-centre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!