我有两个不同的结构数组,我想为其构建配方:
typeof(nodes) == Array{Node{TF}, 1}
和typeof(elements) == Array{Element{TF}, 1}
(其中TF
通常是Float64
)。我希望能够执行类似 plot(nodes, elements)
之类的操作并取回绘图对象,而无需将 Plots
添加到我的包中,我更喜欢重量较轻的 RecipesBase
。
我已经阅读了文档、概述以及关于使用RecipesBase
的
讨论。
我能够通过创建一个占位符结构
NodeMesh
来让用户配方工作,它只保存数组 nodes
和 elements
。配方的函数签名如下所示:@recipe function plot_mesh(nodemesh::NodeMesh)
。 (然后我立即解压配方中的结构。)
这种做法似乎……错误?我的意思是它有效,但我也可以定义一个返回传递给 Plots 的字典的函数。看起来系列食谱是正确的解决方案,但我无法让它发挥作用。我尝试了函数签名的几种不同变体(所有这些都不起作用):
@recipe function f(::Type{Val{:gxmesh}}, nodes, elements)
@recipe function plot_mesh(nodes::Vector{Node}, elements::Vector{MeshElement})
@recipe function plot_mesh(nodes::Array{Node}, elements::Array{MeshElement})
正确的做法是什么?我错过了什么?
我在RecipeBase
的问题
中找到了潜在的答案。
以下是我更改有效函数签名的方法:
@recipe function plot_mesh_recipe(nodes::Array{T1, 1}, elements::Array{T2, 1}) where {T1<:Node, T2<:MeshElement}
该函数返回我想要绘制的内容的 x 和 y。