如何使用Julia绘制或显示多个图像在一行中?

huangapple go评论55阅读模式
英文:

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 a matrix with size 28 x 28. Let's assume I store them in an 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 has something like dynamic layout for its plots, and I can show an image in each subplot and display them in a window with something like this:

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

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)

答案1

得分: 3

你没有提到你正在使用哪个绘图库,但从基本的语法来看,我模糊地猜测你可能在询问关于 Plots.jl 的问题。

Plots 中,原则上,要在一个图中绘制多个子图,可以这样操作:

using Plots

p1 = plot(rand(5))

p2 = plot(rand(5))

plot(p1, p2)

也就是说,你可以使用 plot 并传入多个参数,这些参数本身是绘图对象。此外,你还可以指定一个 layout 参数,它的最简单形式是一个元组 (nrows, ncols),用于将子图放置在具有指定行数和列数的网格中。

举个例子,下面是三个并排的绘图:

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

如何使用Julia绘制或显示多个图像在一行中?

英文:

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))

如何使用Julia绘制或显示多个图像在一行中?

huangapple
  • 本文由 发表于 2023年2月8日 18:25:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75384383.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定