为什么Inset项目不能在Prolog中显示? [英] Why doesn't the Inset item show in Prolog in a plot?

查看:112
本文介绍了为什么Inset项目不能在Prolog中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个问题的长度表示歉意。我目前的Mathematica编程项目涉及复制我的雇主机构对时间序列的出版质量图的非常具体的业务规则。其中一条规则是多面板图的面板标题和字幕集中在绘图区域的顶部附近。这工作得很好,使用 Prolog Inset ,直到我重新设置了该函数的位以允许显式还包括Prolog 元素。然后只有在 Prolog 选项中传递的项目才会显示,而不是面板标题和字幕。如果没有明确的 Prolog 选项,面板标题和字幕显示正常。

为了进一步说明,假设函数体都在一个很大的 Module 中,包括局部变量 pl = OptionValue [Prolog] 熔点= OptionValue [多面板]

这个定义( ppl title 字幕也被定义为局部变量,并且 Rfont framecol 是包中其他地方定义的常量,即ArialBlack):

  ppl = If [mp === False,pl,If [Length [pl]> 0,Join [{
如果[ToString [subtitle] ==None,Inset [
DisplayForm [GridBox [{{Style [title,20,FontFamily - > Rfont,framecol]}}]],
Scaled [{0.5,0.96}],{Center,Top}],
Inset [DisplayForm [$ {$ b $ GridBox [{{Style [title,20 ,FontFamily - > Rfont,framecol]},
{Style [subtitle,16,FontFamily - > Rfont,framecol]}},
RowSpacings - >如果[ToString [subtitle] ==None,
Inset [DisplayForm [0]],Scaled [{0.5,0.98}],{Center,Top}]],pl],
{
GridBox [{{Style [title,20,FontFamily - > Rfont,framecol]}}]],
Scaled [{0.5,0.96}],{Center,Top}],
Inset [DisplayForm [$ {$ b $ GridBox [{{Style [title,20 ,FontFamily - > Rfont,framecol]},
{Style [subtitle,16,FontFamily - > Rfont,framecol]}},
RowSpacings - > 0]],Scaled [{0.5,0.98}],{Center,Top}]]}]]



<尽管如此,所有的事情都很好。如果选项 MultiPanel (并因此 mp ),则使用 Inset >)不是 False 并且没有 Prolog 显式设置。但是,如果设置了序言,例如 Prolog - > {Text [test,Scaled [{0.6 ,0.5 }]]} ,则 Inset 不显示,只有 Text 元素。



这不是问题我一起加入他们的方式。捕获并打印 ppl 的值给出:

  {Inset [{ {Style [这是一个测试,LineColor  - > GrayLevel [0],
FrontFaceColor - > GrayLevel [0],BackFaceColor - > GrayLevel [0],
GraphicsColor - > GrayLevel [0],FontFamily - > Arial,FontSize - > 20,
FontColor - > GrayLevel [0]]},
{Style [年终百分比变化,LineColor - > GrayLevel [0],
FrontFaceColor - > GrayLevel [0],BackFaceColor - > GrayLevel [0],
GraphicsColor - > GrayLevel [0],FontFamily - > Arial,FontSize - > 16,
FontColor - > GrayLevel [0]]}},
已缩放[{0.5,0.98}],{Center,Top}],Text [test,Scaled [{0.6,0.5}]]}

(是的,这些是一些未记录的选项,我会在另一个问题中询问。)



有人知道是否有任何阻止 Prolog (或 Epilog 在这一套图形选项中结合了 Inset 元素和其他东西?

解决方案

现在我觉得有点蠢。我解决了这个问题。让我看看我能否清楚解释。假设你有一个自定义函数(比如 XYZPlot ),它建立在一个内建的函数上(比如说, DateListPlot )。假设你想传递一些选项给 DateListPlot ,并且处理一些特定于 XYZPlot 的选项。然后,您可能希望传递用户在之前显式包含的任何选项,以传递适用于您的自定义函数的默认选项。这是一个玩具的例子:通常你会用 SetOptions 等来设置默认的 PlotRange 作为你自定义函数的一个选项。

  defaultplotrange = {1,5}; 
XYZPlot [args ___,opts:OptionsPattern [{XYZPlot,DateListPlot}]]:=
DateListPlot [args,Sequence @@ FilterRules [{opts},Options [DateListPlot]],
PlotRange- > defaultplotrange]

到目前为止这么好。但是,如果您想捕捉选项的价值并对其进行修改,即使用户在调用该函数时为其提供了明确的值,例如添加[ahem]面板标题(如果有其他选项)设置为 True ,那么你不能把这个选项放在 FilterRules 位之后。它必须早于之前。否则,将使用用户给出的 Prolog 的值,而不是添加了位的那个值。所以正确的做法是做这样的事情。

  defaultplotrange = {1,5}; 
使用[{pl = OptionValue [Prolog],mp = OptionValue [MultiPanel]},
DateListPlot [args ___,opts:OptionsPattern [{XYZPlot,DateListPlot}]]:=

Prolog - >如果[mp === False,pl,Join [pl,{Inset [(* something else *)]}]],
Sequence @@ FilterRules [{opts},Options [DateListPlot]],
plotRange-> defaultplotrange]]

抱歉打扰您。


I apologise for the length of this question. My current Mathematica programming project involves replicating the very specific business rules my employing institution has for publication-quality plots of time series. One of these rules is that multipanel graphs have panel titles and subtitles centered near the top of the plot area. This worked fine using Prolog and Inset until I redid that bit of the function to allow explicit Prolog elements to be included as well. Then only the item passed in the Prolog option shows, not the panel titles and subtitles. If there is no explicit Prolog option, the panel titles and subtitles show up fine.

To explicate a bit further, imagine the function body is all in a big Module, including the local variable pl=OptionValue[Prolog] and mp=OptionValue[MultiPanel].

A bit further down is this definition (ppl, title and subtitle were also defined as local variables, and Rfont and framecol are constants defined elsewhere in the package, namely to be "Arial" and "Black"):

ppl=If[mp===False,pl,If[Length[pl]>0,Join[{ 
If[ToString[subtitle] == "None",  Inset[
DisplayForm[GridBox[{{Style[title, 20, FontFamily -> Rfont, framecol]}}]],
    Scaled[{0.5,0.96}],{Center,Top} ], 
Inset[DisplayForm[
GridBox[{{Style[title, 20, FontFamily -> Rfont, framecol]}, 
     {Style[subtitle, 16, FontFamily -> Rfont, framecol]}}, 
     RowSpacings -> 0]],Scaled[{0.5,0.98}],{Center,Top}] ]},pl],
  {If[ToString[subtitle] == "None",  
     Inset[ DisplayForm[
       GridBox[{{Style[title, 20, FontFamily -> Rfont, framecol]}}]],
      Scaled[{0.5,0.96}],{Center,Top} ], 
      Inset[DisplayForm[
        GridBox[{{Style[title, 20, FontFamily -> Rfont, framecol]}, 
                  {Style[subtitle, 16, FontFamily -> Rfont, framecol]}},
        RowSpacings -> 0]],Scaled[{0.5,0.98}],{Center,Top}]] }] ]

All fine as far as it goes. The Inset is used if the option MultiPanel (and thus mp) is not False and there is no Prolog explicitly set. But if a prolog is set, e.g., Prolog -> {Text["test", Scaled[{0.6, 0.5}]]}, then the Inset doesn't show, only the Text element.

It isn't a problem with the way I am joining them together. Capturing and printing the value of ppl gives:

{Inset[{{Style["This is a test", LineColor -> GrayLevel[0], 
FrontFaceColor -> GrayLevel[0],   BackFaceColor -> GrayLevel[0], 
GraphicsColor -> GrayLevel[0], FontFamily -> "Arial", FontSize -> 20, 
FontColor -> GrayLevel[0]]}, 
{Style["Year-ended percentage change", LineColor -> GrayLevel[0], 
FrontFaceColor -> GrayLevel[0], BackFaceColor -> GrayLevel[0], 
GraphicsColor -> GrayLevel[0], FontFamily -> "Arial", FontSize -> 16, 
FontColor -> GrayLevel[0]]}}, 
Scaled[{0.5, 0.98}], {Center, Top}], Text["test", Scaled[{0.6, 0.5}]]}

(And yes, those are a bunch of undocumented options which I shall ask about in another question.)

Does anyone know if there is anything preventing Prolog (or Epilog for that matter) combining Inset elements and other things in the one set of graphics options?

解决方案

I feel a bit stupid now. I worked out the issue. Let me see if I can explain clearly enough.

Suppose you have a custom function (say, XYZPlot) that is built on a built-in one (say, DateListPlot). Suppose you want to pass some options to DateListPlot, as well as handling some options that are specific to XYZPlot. Then you probably want to pass any options the user includes explicitly before you pass the default options that apply to your custom function. This is a toy example: normally you'd set default PlotRange as an option to your custom function with SetOptions etc.

defaultplotrange = {1,5};
XYZPlot[args___,opts:OptionsPattern[{XYZPlot,DateListPlot}]]:=
  DateListPlot[args,Sequence @@ FilterRules[{opts}, Options[DateListPlot]],
    PlotRange->defaultplotrange]

So far so good. But if you want to catch the value of an option and modify it even if the user provides an explicit value for it when they call the function, for example to add [ahem] panel titles if some other option is set to True, then you can't put that option after the FilterRules bit. It has to come before. Otherwise the value of Prolog that the user gave will be used, not the one with the bit added. So the right way is to do something like this.

defaultplotrange = {1,5};
XYZPlot[args___,opts:OptionsPattern[{XYZPlot,DateListPlot}]]:=
  With[{pl=OptionValue[Prolog],mp=OptionValue[MultiPanel]},
  DateListPlot[args,
  Prolog -> If[mp===False,pl,Join[pl,{Inset[(* something else *)]}]],
  Sequence @@ FilterRules[{opts}, Options[DateListPlot]],
    PlotRange->defaultplotrange]]

Sorry to bother you all.

这篇关于为什么Inset项目不能在Prolog中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆