If I execute the following command:
for file in files:
display(Image(filename=os.path.join(folder,file)))
I get a list of images in a column:
How to put them in a row (horizontally)?
Python solution We could use the Image class of IPython. display to load and display a local image in the IPython notebook. Here, I have used the Image( ) function, where one needs to supply the filename i.e., the location path for the image file. Additionally, we can vary the width and height to adjust the image size.
To display the image, the Ipython. display() method necessitates the use of a function. In the notebook, you can also specify the width and height of the image.
Insert image from URL Create some repository and upload an image file there (this can be easily done on the GitHub website). Then click on the image and click on the Download button. The GitHub will open a new tab with your image. You can use the URL address in the Jupyter Notebook.
This worked for me:
from matplotlib.pyplot import figure, imshow, axis
from matplotlib.image import imread
def showImagesHorizontally(list_of_files):
fig = figure()
number_of_files = len(list_of_files)
for i in range(number_of_files):
a=fig.add_subplot(1,number_of_files,i+1)
image = imread(list_of_files[i])
imshow(image,cmap='Greys_r')
axis('off')
You can also use HTML:
from IPython.display import display, HTML
def make_html(folder, image):
return '<img src="{}" style="display:inline;margin:1px"/>'
.format(os.path.join(folder, image))
display(HTML(''.join(make_html(f, x)) for x in files))
In my case, by setting a margin will fix the un-alignment (and IMHO produce nicer results).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With