查找绘图的最终显示区域中的框架/轴的坐标
如果我使用 Frame->True 进行绘图,有没有办法可以在图像的绝对坐标中找到框架角的坐标?我有 PlotRange 和 PlotRangePadding 的数值,但请注意,我不想以任何方式篡改实际绘图,只需找出 Mathematica 在完整显示区域中选择放置绘图的框架/轴的位置即可。
正如 Brett Champion 所指出的,我正在寻找坐标 {x,y} 使得 Scaled[{0,0}] == ImageScaled[{x,y}]。
[请注意,我编辑了这个问题,以消除对术语“缩放坐标”的令人困惑的误用。]
If I do a Plot with Frame->True is there a way I can find the coordinates of the corners of the Frame in the absolute coordinates of the image? I have the numerical values of PlotRange and PlotRangePadding but note that I don't want to tamper with the actual plot in any way, just find out where in the full display area Mathematica chooses to place the frame/axes of the plot.
As pointed out by Brett Champion, I'm looking for the coordinates {x,y} such that Scaled[{0,0}] == ImageScaled[{x,y}].
[Note that I edited this question to remove my confusing misuse of the term "scaled coordinates".]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
框架的角位于
Scaled[{0,0}]
和Scaled[{1,1}]
处。完整图形(包括标签)的角点位于
ImageScaled[{0,0}]
和ImageScaled[{1,1}]
处。它们之间的转换很困难,尽管理论上如果您知道
PlotRange
和PlotRangePadding 的实际数字设置,则可以转换
。Scaled
和用户(未缩放)坐标根据您的应用程序,您也许还可以使用 MousePosition,它也知道这些事情。
Rasterize(和 HTML 导出)还知道如何在位图/像素坐标系中查找注释的边界框:
以下是 dreeves 如何使用 Rasterize 技巧来创建一个函数来准确返回他正在寻找的内容(注意全局变量 imgsz 的假设,它提供了用于光栅化绘图的 ImageSize 选项——框架的坐标取决于该值):
The corners of the frame are at
Scaled[{0,0}]
andScaled[{1,1}]
.The corners of the full graphic (including labels) are at
ImageScaled[{0,0}]
andImageScaled[{1,1}]
.Converting between them is hard, although in theory it's possible to convert
Scaled
and user (unscaled) coordinates if you know the actual, numeric, settings forPlotRange
andPlotRangePadding
.Depending on your application, you might also be able to use MousePosition, which knows these things as well.
Rasterize
(and HTML export) also know how to find bounding boxes of annotations, in a bitmap/pixel coordinate system:Here's how dreeves used that Rasterize trick to make a function to return exactly what he was looking for (note the assumption of a global variable
imgsz
which gives the ImageSize option for rasterizing the plot -- the coordinates of the frame depend on that value):框架左上角的坐标始终为
Scaled[{0,1}]
。框架右下角的坐标始终为
Scaled[{1,0}]
。让我们在左上角和右下角放置大点:
当我单击图形(见下文)时,很明显,图框周围没有填充。
现在,启用
ImagePadding
,让我们放置Point
在相同的角上:点
位于图框的角上。图框周围有
ImagePadding
。编辑:基于 dreeves 对问题的澄清。
我将绘图绘制为 300x300 以简化数字。
这是分析。
ImagePadding
“是在ImageSize中定义的”。ImageScaled[{.1,.1}]
、ImageScaled[{.9,.1}
、>ImageScaled[{.9,.9}]
&ImageScaled[{.1,.9}]
。计算其他
AspectRatio
和ImageSize
的值很容易。The coordinates of the upper left corner of the frame are always
Scaled[{0,1}]
.The coordinates of the lower right corner of the frame are always
Scaled[{1,0}]
.Let's place large points at the upper left and lower right corners:
When I click on the graph (see below) , it is obvious that there is no padding around the frame of the plot.
Now, with
ImagePadding
on, let's placePoint
s in the same corners:The
Point
s stay at the corners of the graph frame.There is
ImagePadding
around the graph frame.EDIT: Based on the clarification of the question by dreeves.
I've drawn the plot as 300x300 to simplify the numbers.
Here's the analysis.
ImagePadding
"is defined within ImageSize".ImageScaled[{.1,.1}]
,ImageScaled[{.9,.1}
,ImageScaled[{.9,.9}]
&ImageScaled[{.1,.9}]
.It's easy to work out the value for other
AspectRatio
s andImageSize
s.一种可能性是手动控制 ImagePadding:
One possibility is to take manual control of ImagePadding: