获取手动绘制点的坐标 [英] Getting coordinates of manually drawn points

查看:29
本文介绍了获取手动绘制点的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图表作为执行 ListPlot[] 函数的结果.我可以通过将点移动到不同的位置来手动编辑此图形并使用绘图工具添加新点.

I have a graph as a result of executing ListPlot[] function. I can manually edit this graph by moving points to a different location and also adding new points using the Drawing Tools.

如何从编辑后的图形中获取新点和更改点的坐标?

How do I get the coordinates of new and changed points from the edited graphics?

推荐答案

这种方法使每个数据点都成为可以移动的定位器.可以根据需要添加新定位器并删除旧定位器.每次更改后都会更新最佳拟合和方差.

This approach makes every data point a locator that can be moved. New locators can be added and old ones deleted as appropriate. The best fit and variance are updated after every change.

这里有一些指数增长的数据,有一些错误和一个数据点缺失

Here's some data of some exponential growth with some errors and a data point missing

data = Delete[Table[{t, (1 + RandomReal[{-.2, .2}])Exp[t]}, {t, 0, 2, .2}], 6];

一个小小的格式化命令:

A little formatting command:

nForm = NumberForm[#, {2, 2}, NumberPadding -> {"", "0"}] &;

最后,这是制作可操作图形的代码.使用Alt-Click添加新的定位器/数据点code>(或 Ctrl-Alt-Click 在 linux 上).如果您单击左侧的点列表,则会打开一个包含输入表单中的点的新窗口.

Finally, here's the code to make the manipulable graphics. New locators/data points are added using Alt-Click (or Ctrl-Alt-Click on linux). If you click on the list of points on the left, then a new window is opened containing the points in input form.

Manipulate[
 LocatorPane[Dynamic[pts, {None, Temporary, Automatic}],
  nlm = Block[{a,b,t}, NonlinearModelFit[Sort[pts], a Exp[t] + b, {a, b}, t]]; 
  Show[Plot[{Exp[t], nlm[t]}, {t, 0, 2}, 
    PlotStyle -> {{Thick, LightGray}, Dotted}, PlotRangePadding -> Scaled[0.1]], 
   ListPlot[data, PlotStyle -> Blue], AxesLabel -> Block[{t,f}, {t, f[t]}]],
  LocatorAutoCreate -> True, Appearance -> Style["\[CircleDot]", Red]],
 {nlm, None}, {{pts, data}, None},
 Dynamic[Pane[EventHandler[
    nForm@Grid[Prepend[pts, {"x", "y"}], Dividers -> {False, 2 -> True}], 
    {"MouseClicked" :> (CreateDocument[{ExpressionCell[nlm["Data"], "Output"]}, 
     WindowTitle -> "Data"])}], ImageSize -> {100, 250}, 
   ImageSizeAction -> "Scrollable", Scrollbars -> {False, True}]],
 Pane[Dynamic[nForm@Row@{nlm,Row[{"\tvariance = ",nlm["EstimatedVariance"]}]}]],
 ControlPlacement -> {Left, Left, Left, Top}]

在上面,我使用定位器纠正了几个异常值并恢复了丢失的数据点.

In the above I've used the locators to correct a couple of outliers and restored the missing data point.

这篇关于获取手动绘制点的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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