我想用布局绘制一个绘图向量,但我找不到如何使其工作:
using Plots
# First I create 2*n plots
n = 1
myPlots = Vector{Any}([])
for i in 1:2*n
p = plot(rand(10), rand(10))
push!(myPlots, p)
end
# Then I want to display them on 2 rows and n columns
plot(myPlots[1], myPlots[2], layout = (2, n)) # Works (but only for n=1)
plot(myPlots, layout = (2, n)) # Does not work
最后一行返回以下错误:
ERROR: MethodError: no method matching getindex(::Nothing, ::Int64)
Stacktrace:
[1] _apply_type_recipe(plotattributes::Any, v::AbstractArray, letter::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/type_recipe.jl:43
[2] macro expansion
@ ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:140 [inlined]
[3] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, y::Any)
@ RecipesPipeline ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
[4] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
[5] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
[6] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:223
[7] plot(args::Any; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
@ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:102
[8] generateGraphics(; nValues::Vector{Int64}, pValues::Vector{Int64})
@ Main ~/OneDrive/31_Recherche/p-centers/src/2023-12_test_clustering_cristian/results/2024-01-19_expe_article/generateGraphics.jl:41
[9] generateGraphics()
@ Main ~/OneDrive/31_Recherche/p-centers/src/2023-12_test_clustering_cristian/results/2024-01-19_expe_article/generateGraphics.jl:17
[10] top-level scope
@ REPL[68]:1
您能告诉我显示带有布局的向量中包含的非指定数量的绘图的语法吗?
我对 Plots.jl 不太熟悉,但我不确定你是否可以绘制
Plot
。您绘制数据,您显示绘图。如果你把所有东西都放在 Vector{Any}
中,那就更难了。尽可能避免收集Any
。
这可行,也许它适合您的需求:
n = 3
data = [(rand(10), rand(10)) for _ in 1:2n]
plot(data; layout=(2, n))