RecipesBase:如何为两个结构数组创建配方

问题描述 投票:0回答:1

我有两个不同的结构数组,我想为其构建配方:

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

正确的做法是什么?我错过了什么?

julia julia-plots
1个回答
0
投票

我在RecipeBase的问题

中找到了
潜在的答案。

以下是我更改有效函数签名的方法:

@recipe function plot_mesh_recipe(nodes::Array{T1, 1}, elements::Array{T2, 1}) where {T1<:Node, T2<:MeshElement}

该函数返回我想要绘制的内容的 x 和 y。

© www.soinside.com 2019 - 2024. All rights reserved.