LevelScheme 中的直方图
我刚刚开始使用 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
的 PlotRange
,而是遵循主 Figure
的 PlotRange
。当直方图
被绘图
或类似命令替换时,不会发生此行为。因此,以下内容会生成一个干净的图
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}}]
还有其他人遇到过此问题吗?或者,您有修复建议吗?
编辑
我想我应该在问题中添加一些绿色。我仍然有兴趣知道如何克服这个障碍。
I've just started using LevelScheme, and have issues with getting the histogram to fit correctly within the figure. A minimal non-working example:
<<"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}}]
The output looks like this
when it should look like this
Basically, the Histogram
graphics object doesn't obey the FigurePanel
's PlotRange
, but instead obeys the main Figure
's PlotRange
. This behaviour doesn't occur when the Histogram
is replaced by a Plot
or similar commands. So the following produces a clean plot
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}}]
Has anyone else encountered this issue? Or, do you have suggestions for a fix?
EDIT
I thought I'd add some green to the question. I'm still interested in knowing how to overcome this hurdle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我猜你不会太喜欢这个,但它是一种解决方法。
如果我给出 PerformanceGoal -> “速度” 作为直方图选项(而不是
PerformanceGoal ->“质量”
),我禁用了交互行为,但是,通过一些小的调整,我得到以下结果:Well, I recon you won't like this one too much but it is a workaround of sorts.
If I give
PerformanceGoal -> "Speed"
as a Histogram option (rather thanPerformanceGoal -> "Quality"
) I disable interactive behaviour but, with a few minor tweaks, I get the following:正如 Simon 在评论中提到的,您可以使用 LevelScheme 的 DataPlot 来绘制直方图。
但是,我还没有像
Histogram 或
BarChart
,如果这也是您的意图。顺便说一句,函数
histData
类似于我很久以前在 mathematica 帮助论坛上看到的东西,它出现在我有用的函数工具包中。我不记得我在哪里或何时读到的,归功于它。然而,现在对我来说,这并不像当时那样具有神奇的功能。As Simon mentioned in a comment, you can use
LevelScheme
'sDataPlot
to plot a histogram.However, I haven't managed to get filled histogram bars like that produced by
Histogram
orBarChart
, if that was also what you had intended.BTW, the function
histData
is similar to something I saw on a mathematica help forum long ago, and it went in my useful functions toolkit. I don't remember where I read that or when, to credit it. However, it is not all that of a magic function now to me, as it was back then.我知道问题出在哪里,但我没有立即解决的办法。 LevelScheme 的工作方式是转换
Graphics
对象,以便它们正确适合。为此,RawGraphics
使用LegacyPackages\Graphics\Graphics.m
中的旧函数TransformGraphics
,该函数包含在LegacyTransformGraphics.m< /code> 在 LevelScheme 包的 v. 3.51 中。查看
Histogram
的FullForm
,您可以看到TransformGraphics
对处理生成的对象类型一无所知。 Mark Caprio 正在接下来的几个月内对 LevelScheme 进行更新,因此可能会进行修复。同时,在将直方图提供给RawGraphics
之前尝试使用Rasterize
,尽管它可能不会给您带来好的结果。编辑:
更新的版本可能看起来像这样,而不是使用旧版本的 TransformGraphics
当然,现在的技巧是提供一个可以实现 GeometricTransformation 的
transform
版本> 可以接受。尽管旧版 TransformGraphics 将函数(其第二个参数)直接应用于 g 中找到的点,因此使用上述代码无需进行任何其他更改即可工作。要尝试它,请在 LevelScheme.nb(并重新生成 LevelScheme.m)或直接在 LevelScheme.m 中将
Needs["LevelScheme`LegacyTransformGraphics`"]
替换为上述代码。它可能无法完全工作,因为我看不到选项在哪里被替换,但这应该是一个开始。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 functionTransformGraphics
fromLegacyPackages\Graphics\Graphics.m
which is included inLegacyTransformGraphics.m
in v. 3.51 of the LevelScheme packages. Looking at theFullForm
of yourHistogram
, you can see thatTransformGraphics
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 usingRasterize
before supply your histogram toRawGraphics
, although it may not give you good results.Edit:
Instead of using the legacy version of
TransformGraphics
, a more recent version might look likeOf course, the trick is now supplying a version of
transform
thatGeometricTransformation
can accept. Although, the legacyTransformGraphics
, applies a function, its second argument, directly to the points found ing
, 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.