我不确定以下是否是您想要的,但尽管如此:
如果我使用ListPlot
如下:
lp1 = Labeled[
ListPlot[Diagonal@Table[{x, y}, {x, 0, 5}, {y, 5}],
PlotStyle -> {Directive[Red, PointSize[Large]]}], "lp1"];
通过双击其中一个红点两次以将选择范围设置为点的级别,然后我可以移动各个点,例如使点位于曲线(而不是直线)上。我现在想提取这些点(并说在新的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}}];
修改Yaroslav Bulatov最初建议的一个非常有用的方法,可能会发现here https://stackoverflow.com/questions/4245946/vertexcoordinate-rules-and-vertexlist-from-graphplot-graphic/4250069#4250069
modpoints = Flatten[Cases[expr, PointBox[___], Infinity][[All, 1]], {{2, 1}}]
EDIT
正如 belisarius 所指出的,希望能够提取“手动”添加的点(可以使用绘图工具选项板中的“点”将其添加到生成的图中)。更好的提取方法(在“显示表达式”之后...)可能如下:
modpoints = Cases[Cases[expr, PointBox[___],
Infinity], {_?NumericQ, _?NumericQ}, Infinity]
当然,“表现表情”并不是唯一的方法。
InputForm
是另一种可能性。例如,
expr2 = InputForm[ListPlotGraphic]
modpoints = Cases[Cases[expr, Point[___],
Infinity], {_?NumericQ, _?NumericQ}, Infinity]
其中“ListPlotGraphic”是修改后的图形(通过“复制和粘贴”插入),也将起作用。
示例图
Addendum
以上可以通过一些笔记本编程来自动化:
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]]]]]
运行上面的代码,移动最后两个原始(红色)点并使用绘图工具添加几个蓝色的额外点,然后按下按钮产生
可以看到有一个PointBox
对于原始数据和新数据PointBox
对于每个添加的点。当然,通过修改上面的代码,你可以做的不仅仅是简单地打印出原始点坐标。