Max*_*Max 4 wolfram-mathematica
我有一个图表作为执行ListPlot[]功能的结果.我可以通过将点移动到其他位置并使用绘图工具添加新点来手动编辑此图形.
如何从编辑的图形中获取新点和更改点的坐标?
我不确定以下内容是否符合您的要求,但仍然如此:
如果我使用ListPlot如下:
lp1 = Labeled[
ListPlot[Diagonal@Table[{x, y}, {x, 0, 5}, {y, 5}],
PlotStyle -> {Directive[Red, PointSize[Large]]}], "lp1"];
Run Code Online (Sandbox Code Playgroud)
通过双击其中一个红点两次以获得点的水平,我可以移动各个点,例如,使点位于曲线上(而不是直线).我现在想要提取这些点(并说在新的中使用它们ListPlot)[见下面的图表]
如果我单击绘图图形的括号并使用"显示表达式"(Mac上的命令Shift E),我可以"看到"可以提取的修改点的坐标.例如:
expr = Cell[
BoxData[GraphicsBox[{RGBColor[1, 0, 0], PointSize[Large],
PointBox[{{0., 1.}, {0.8254488458250212,
2.886651181634783}, {1.9301795383300084`,
3.925201233010209}, {3.046546974446661,
4.597525796319094}, {4., 5.}}]},
AspectRatio -> NCache[GoldenRatio^(-1), 0.6180339887498948],
Axes -> True, PlotRange -> Automatic,
PlotRangeClipping -> True]], "Input",
CellChangeTimes -> {{3.504427833788156*^9, 3.50442786823486*^9}}];
Run Code Online (Sandbox Code Playgroud)
修改了Yaroslav Bulatov最初提出的非常有用的方法,可以在这里找到
modpoints = Flatten[Cases[expr, PointBox[___], Infinity][[All, 1]], {{2, 1}}]
Run Code Online (Sandbox Code Playgroud)
正如belisarius所指出的,希望能够提取"手动"添加的点(可以使用"绘图工具"调色板中的"点"将其添加到生成的绘图中).一种更好的提取方法(在"显示表达式"之后......)可能如下:
modpoints = Cases[Cases[expr, PointBox[___],
Infinity], {_?NumericQ, _?NumericQ}, Infinity]
Run Code Online (Sandbox Code Playgroud)
当然,'Show Expression'不是唯一的方法.
InputForm是另一种可能性.例如,
expr2 = InputForm[ListPlotGraphic]
modpoints = Cases[Cases[expr, Point[___],
Infinity], {_?NumericQ, _?NumericQ}, Infinity]
Run Code Online (Sandbox Code Playgroud)
其中"ListPlotGraphic"是修改后的图形(通过"复制和粘贴"插入),也可以使用.
示例图

以上可以通过一点笔记本编程自动化:
lp1 = Labeled[
ListPlot[Diagonal@Table[{x, y}, {x, 0, 5}, {y, 5}],
PlotStyle -> {Directive[Red, PointSize[Large]]}],
Button["Print points",
With[{nb = ButtonNotebook[]},
SelectionMove[nb, All, CellContents];
Print[Cases[NotebookRead[nb],
PointBox[{{_?NumericQ, _?NumericQ} ..}] |
PointBox[{_?NumericQ, _?NumericQ}], Infinity]]]]]
Run Code Online (Sandbox Code Playgroud)
运行上面的步骤,移动最后两个原始(红色)点,并使用绘图工具添加一些蓝色的额外点,然后按下按钮

您可以看到PointBox原始数据有一个PointBox,每个添加点都有一个新数据.当然,通过修改上面的代码,您可以做的不仅仅是打印原始点坐标.