6

我刚刚开始使用LevelScheme,并且在使直方图正确地适合图形时遇到了问题。一个最小的非工作示例:

<<"LevelScheme`"
Figure[{FigurePanel[{{0, 1}, {0, 1}},
   LabB -> textit["x"], BufferB -> 2.5,
   LabL -> textit["p(x)"], BufferL -> 2.5,
   FrameTicks -> {LinTicks[-4, 4], LinTicks[0, 1]},
   PlotRange -> {{-3, 3}, {0, 0.5}}], 
  RawGraphics[
   Histogram[RandomReal[NormalDistribution[], 1000], Automatic, 
    "ProbabilityDensity"]]},
 Frame -> False, PlotRange -> {{-0.075, 1.1}, {-0.1, 1.03}}]

输出看起来像这样

在此处输入图像描述

当它看起来像这样

在此处输入图像描述

基本上,Histogram图形对象不服从FigurePanel's PlotRange,而是服从 main Figure's PlotRangeHistogram当替换为 aPlot或类似命令时,不会发生此行为。所以下面会产生一个干净的情节

Figure[{FigurePanel[{{0, 1}, {0, 1}},
   LabB -> textit["x"], BufferB -> 2.5,
   LabL -> textit["p(x)"], BufferL -> 2.5,
   FrameTicks -> {LinTicks[-4, 4], LinTicks[0, 1]},
   PlotRange -> {{-3, 3}, {0, 0.5}}], 
  RawGraphics[Plot[1/Sqrt[2 Pi] Exp[-x^2/2], {x, -4, 4}]]},
 Frame -> False, PlotRange -> {{-0.075, 1.1}, {-0.1, 1.03}}]

在此处输入图像描述

有没有其他人遇到过这个问题?或者,您有修复建议吗?

编辑

我想我会为这个问题添加一些绿色。我仍然有兴趣知道如何克服这个障碍。

4

3 回答 3

4

好吧,我估计你不会太喜欢这个,但它是一种解决方法。

如果我PerformanceGoal -> "Speed"作为直方图选项(而不是PerformanceGoal -> "Quality")给出,我会禁用交互行为,但是通过一些小的调整,我会得到以下信息:

<< "LevelScheme`"
Figure[{FigurePanel[{{0, 1}, {0, 1}}, LabB -> textit["x"], 
   BufferB -> 2.5, LabL -> textit["p(x)"], BufferL -> 2.5, 
   FrameTicks -> {LinTicks[-4, 4], LinTicks[0, 1]}, 
   PlotRange -> {{-3, 3}, {0, 0.55}}], 
  RawGraphics[
   Histogram[RandomReal[NormalDistribution[], 1000], Automatic, 
    "ProbabilityDensity", PerformanceGoal -> "Speed"]]}, 
 Frame -> False, PlotRange -> {{-0.075, 1.1}, {-0.15, 1.1}}]

在此处输入图像描述

于 2011-04-27T15:57:22.650 回答
2

正如西蒙在评论中提到的那样,您可以使用LevelScheme'sDataPlot来绘制直方图。

<< "LevelScheme`"
histData[x_] := 
  Cases[x, RectangleBox[{bl_, _}, {br_, c_}] :> {{bl, br}, c}, 
   Infinity];
hist = histData[
   Histogram[RandomReal[NormalDistribution[], 1000], {-4, 4, 0.1}, 
    "ProbabilityDensity"]];
bins = hist[[All, 1, 1]]; counts = hist[[All, 2]];
data = Table[{bins[[i]], counts[[i]]}, {i, 1, Length@counts}];

Figure[{FigurePanel[{{0, 1}, {0, 1}}, LabB -> textit["x"], 
   BufferB -> 2.5, LabL -> textit["p(x)"], BufferL -> 2.5, 
   FrameTicks -> {LinTicks[-4, 4], LinTicks[0, 1]}, 
   PlotRange -> {{-3, 3}, {0, 0.5}}],
  DataPlot[data, 
   DataLine -> {LineShape -> "Histogram", LineColor -> Darker@Blue}, 
   DataSymbol -> {SymbolSize -> 0.00001}],
  RawGraphics[
   Plot[1/Sqrt[2 Pi] Exp[-x^2/2], {x, -4, 4}, 
    PlotStyle -> {Red, Thick}]]
  }, Frame -> False, PlotRange -> {{-0.075, 1.1}, {-0.1, 1.03}}]

在此处输入图像描述

但是,如果这也是您想要的,我还没有设法获得像Histogramor产生的填充直方图条。BarChart

顺便说一句,这个函数histData类似于我很久以前在数学帮助论坛上看到的东西,它包含在我有用的函数工具包中。我不记得我在哪里或何时读到的,要归功于它。然而,现在对我来说,这并不是一个神奇的功能,就像那时一样。

于 2011-04-26T23:25:15.757 回答
1

I know what the problem is, but I don't have an immediate fix. The way LevelScheme works is that it transforms the Graphics objects so that they fit correctly. To do this, RawGraphics uses the legacy function TransformGraphics from LegacyPackages\Graphics\Graphics.m which is included in LegacyTransformGraphics.m in v. 3.51 of the LevelScheme packages. Looking at the FullForm of your Histogram, you can see that TransformGraphics knows nothing about dealing with the sort of objects produced. Mark Caprio is working on an update to LevelScheme over the next couple of months, so there may be a fix on the way. In the mean time, try using Rasterize before supply your histogram to RawGraphics, although it may not give you good results.

Edit: Instead of using the legacy version of TransformGraphics, a more recent version might look like

TransformGraphics[ 
  (g:(Graphics | Graphics3D))[prims__, opts:OptionsPattern[], transform_]:=
    g[ GeometricTransformation[prims, transform], opts ]

Of course, the trick is now supplying a version of transform that GeometricTransformation can accept. Although, the legacy TransformGraphics, applies a function, its second argument, directly to the points found in g, so using the above code may work without any additional changes.

To try it, replace Needs["LevelScheme`LegacyTransformGraphics`"] with the above code in either LevelScheme.nb (and regenerate LevelScheme.m) or in LevelScheme.m directly. It may not work completely, as I don't see where the options are substituted, but it should be a start.

于 2011-03-29T17:19:24.733 回答