dre*_*ves 7 graphics plot wolfram-mathematica image-processing
如果我用Frame-> True进行绘图,有没有办法可以在图像的绝对坐标中找到Frame角的坐标?我有PlotRange和PlotRangePadding的数值,但请注意我不想以任何方式篡改实际绘图,只需找出Mathematica选择放置绘图的框架/轴的完整显示区域的位置.
正如Brett Champion指出的那样,我正在寻找坐标{x,y},使得Scaled [{0,0}] == ImageScaled [{x,y}].
[请注意,我编辑了这个问题,以消除我对"缩放坐标"一词的混淆误用.]
框架的角落是Scaled[{0,0}]
和Scaled[{1,1}]
.
完整图形(包括标签)的角落位于ImageScaled[{0,0}]
和ImageScaled[{1,1}]
.
它们之间的转换是很难的,虽然在理论上有可能转换Scaled
,如果你知道实际的,数字的,设置用户(未缩放)坐标PlotRange
和PlotRangePadding
.
根据您的应用程序,您也可以使用MousePosition,它也知道这些事情.
Rasterize
(和HTML导出)也知道如何在位图/像素坐标系中找到注释的边界框:
In[33]:= Rasterize[
Plot[Sin[x], {x, 0, 10}, Frame -> True,
Prolog -> {LightYellow,
Annotation[Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]], "One",
"Region"]}], "Regions"]
Out[33]= {{"One", "Region"} -> {{22., 1.33573}, {358.9, 209.551}}}
Run Code Online (Sandbox Code Playgroud)
下面是Dreeves如何使用Rasterize技巧使函数返回他正在寻找的内容(注意全局变量的假设,imgsz
它给出了用于栅格化绘图的ImageSize选项 - 帧的坐标取决于该值):
(* Returns the geometry of the frame of the plot:
{width, height, x offset, y offset, total width, total height}. *)
geom[p_Graphics] := Module[{q, x1, y1, x2, y2, xmax, ymax},
q = Show[p, Prolog->{Annotation[Rectangle[Scaled[{0,0}], Scaled[{1,1}]],
"MAGIC00","MAGIC11"]}];
{{x1,y1}, {x2,y2}} = Rasterize[q, "Regions", ImageSize->imgsz][[1,2]];
{xmax,ymax} = Rasterize[p, "RasterSize", ImageSize->imgsz];
{x2-x1, y2-y1, x1, y1, xmax, ymax}]
Run Code Online (Sandbox Code Playgroud)
帧的左上角的坐标始终是Scaled[{0,1}]
.帧的右下角的坐标始终是Scaled[{1,0}]
.
让我们在左上角和右下角放置大点:
Plot[Cos[x], {x, 0, 10}, Frame -> True,
Epilog -> {PointSize[.08], Point[Scaled[{0, 1}]], Point[Scaled[{1, 0}]]} ]
Run Code Online (Sandbox Code Playgroud)
当我点击图表(见下文)时,很明显,图表框架周围没有填充.
现在,ImagePadding
让我们把Point
s放在同一个角落里:
Plot[Cos[x], {x, 0, 10}, Frame -> True,
ImagePadding -> {{37, 15}, {20, 48}},
Epilog -> {PointSize[.08], Point[Scaled[{0, 1}]], Point[Scaled[{1, 0}]]} ]
Run Code Online (Sandbox Code Playgroud)
所述Point
的逗留在图形框架的角部.ImagePadding
图框周围有 .
编辑:基于dreeves对问题的澄清.
Plot[Cos[x], {x, 1, 9}, ImageSize -> 300, AspectRatio -> 1,
Frame -> True, ImagePadding -> 30,
FrameTicks -> {Range[9], Automatic},
Epilog -> {PointSize[.08], Point[Scaled[{0, 1}]], Point[Scaled[{1, 0}]]}]
Run Code Online (Sandbox Code Playgroud)
我把图绘制为300x300以简化数字.这是分析.
ImagePadding
"在ImageSize中定义".ImageScaled[{.1,.1}]
,ImageScaled[{.9,.1}
,ImageScaled[{.9,.9}]
和ImageScaled[{.1,.9}]
.很容易计算出其他AspectRatio
s和ImageSize
s 的价值.