imagejuliaannotatejulia-plots

How to plot or show multiple images in a row using julia?


I'm new to Julia and I used MNIST handwritten digit train data to get multiple images in matrix with size 28 x 28. Let's assume I store them in array img[i] with length n(n is dynamic). I want to show Images in one window such that every image has its own specific label under it.

I tried to search and read documents, currently I use hcat(images_window, img[i]) for all images and plot(images_window) and annotate some text label for each image in specific coordinates. This way is not a good practice and n is not configurable either. I expect Julia have something like dynamic layout for its plots and I can show Image in each subplot and show them in a window with something like this:

plt = plot()
for (i, subplot) in enumerate(plot)
    plot!(plt, subplot, layout(i))
end
display(plt)

Solution

  • You didn't mention which plotting library you are using but from the basic syntax I'm vaguely guessing that you might be asking bout Plots.jl.

    In Plots, plotting multiple subplots on one figure in principle works like this:

    using Plots
    
    p1 = plot(rand(5))
    
    p2 = plot(rand(5))
    
    plot(p1, p2)
    

    i.e., you call plot with multiple arguments which themselves are plots. You can then additionally specify a layout kwarg, which in its simplest form takes a tuple of (nrows, ncols) and places the subplots in a grid with the specified number of rows and columns.

    As an example, here's three plots next to each other:

    plot(plot.([rand(5) for _ ∈ 1:3])..., layout = (1, 3))
    

    enter image description here