问题
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