Wolfram mathematica 如何在ListPlots中注释多个数据集
通常我必须同时可视化多个数据集,通常是在ListPlot或它的日志中。由于数据集的数量通常大于易于区分的线条样式的数量,并且创建大型绘图图例仍然有些不直观,因此我仍在寻找一种好方法来注释绘图中的不同线条/集合。当在屏幕上工作时,工具提示很好,但是如果我需要预览绘图,工具提示没有帮助 最近,我使用Mesh选项来枚举我的数据集,发现了一些奇怪的东西Wolfram mathematica 如何在ListPlots中注释多个数据集,wolfram-mathematica,Wolfram Mathematica,通常我必须同时可视化多个数据集,通常是在ListPlot或它的日志中。由于数据集的数量通常大于易于区分的线条样式的数量,并且创建大型绘图图例仍然有些不直观,因此我仍在寻找一种好方法来注释绘图中的不同线条/集合。当在屏幕上工作时,工具提示很好,但是如果我需要预览绘图,工具提示没有帮助 最近,我使用Mesh选项来枚举我的数据集,发现了一些奇怪的东西 GraphicsGrid[Partition[Table[ListPlot[ Transpose@ Table[{Sin[x], Cos[x], Ta
GraphicsGrid[Partition[Table[ListPlot[
Transpose@
Table[{Sin[x], Cos[x], Tan[x], Cot[x]}, {x, 0.01, 10, 0.1}],
PlotMarkers -> {"1", "2", "3", "4"}, Mesh -> i, Joined -> True,
PlotLabel -> "Mesh\[Rule]" <> ToString[i], ImageSize -> 180], {i,
1, 30}], 4]]
GraphicsGrid[Partition[Table[ListPlot][
转置@
表[{Sin[x],Cos[x],Tan[x],Cot[x]},{x,0.01,10,0.1}],
PlotMarkers->{“1”、“2”、“3”、“4”},网格->i,连接->真,
PlotLabel->“网格\[规则]”ToString[i],ImageSize->180],{i,
1, 30}], 4]]
在我的计算机(Windows 7 x64,Mathematica 8.0.1)上,结果如下所示:
有趣的是,对于网格->2、8和10,结果看起来像我预期的,其余的则不是。要么我不理解网格选项,要么它不理解我
以下是我的问题:
一种方法是分别生成图,然后将它们一起显示。这就产生了比你的文章更像你的代码,因为
PlotMarkers
似乎在处理一个数据集时发挥了我们预期的作用。我们可以使用ColorData
和PlotStyle
获得相同的颜色。结果如下:
ff = {Sin, Cos, Tan, Cot};
plots = Table[ListLinePlot[ff[[i]] /@ Range[0.1, 10, 0.1],
PlotStyle -> {ColorData[1, i]},
PlotMarkers -> i, Mesh -> 22], {i, 1, Length[ff]}];
(* Delete the spurious asymptote looking thingies. *)
plots = DeleteCases[plots, Line[ll_?(Length[#] < 4 &)], Infinity];
Show[plots, PlotRange -> {-4, 4}]
ff={Sin,Cos,Tan,Cot};
plots=表[ListLinePlot[ff[[i]]/@Range[0.1,10,0.1],
PlotStyle->{ColorData[1,i]},
绘图标记->i,网格->22],{i,1,长度[ff]}];
(*删除伪渐近线外观。*)
plots=DeleteCases[plots,Line[ll?(长度[#]<4&]),无穷大];
显示[绘图,绘图范围->{4,4}]
您要绘制可计算曲线还是实际数据 如果是可计算的曲线,则通常使用。 可以使用不同的破折号和厚度来区分灰度打印机上的线条。PlotLegends文档中有许多示例
如果是真实数据,则数据通常足够稀疏,您可以对实际数据点使用
PlotMarkers
(即不指定Mesh
)。您可以使用自动PlotMarkers
,也可以使用自定义PlotMarkers
包括标记来指示各种不确定性。您可以尝试使用这些方法。将每一行做成一个按钮,单击该按钮时,该按钮会识别自身
plot=Plot[{Sin[x],Cos[x]},{x,0,2*Pi}];
sinline=plot[[1,1,3,2]];
cosline=plot[[1,1,4,2]];
message="";
altplot=Append[plot,PlotLabel->Dynamic[message]];
altplot[[1,1,3,2]]=Button[sinline,message="Clicked on the Sin line"];
altplot[[1,1,4,2]]=Button[cosline,message="Clicked on the Cos line"];
altplot
如果添加EventHandler,则可以获取单击的位置,并将带有相关定位标签的插图添加到绘图中。以动态方式包装绘图,使其在每次单击按钮后自动更新。它很好用
针对评论,以下是一个更完整的版本:
plot = Plot[{Sin[x], Cos[x]}, {x, 0, 2*Pi}];
sinline = plot[[1, 1, 3, 2]];
cosline = plot[[1, 1, 4, 2]];
AddLabel[label_] := (AppendTo[plot[[1]],
Inset[Framed[label, Background -> White], pt]];
(* Remove buttons for final plot *)
plainplot = plot;
plainplot[[1, 1, 3, 2]] = plainplot[[1, 1, 3, 2, 1]];
plainplot[[1, 1, 4, 2]] = plainplot[[1, 1, 4, 2, 1]]);
plot[[1, 1, 3, 2]] = Button[sinline, AddLabel["Sin"]];
plot[[1, 1, 4, 2]] = Button[cosline, AddLabel["Cos"]];
Dynamic[EventHandler[plot,
"MouseDown" :> (pt = MousePosition["Graphics"])]]
要添加标签,请单击该行。最终的带注释图表设置为“plainplot”,可打印和复制,不包含动态元素
[当天晚些时候]另一个版本,这次是通用的,基于初始图表。(使用马克·麦克卢尔的部分溶液。)对于不同的绘图,“ff”和“spec”可以根据需要进行编辑
ff = {Sin, Cos, Tan, Cot};
spec = Range[0.1, 10, 0.1];
(* Plot functions separately to obtain line counts *)
plots = Array[ListLinePlot[ff[[#]] /@ spec] &, Length@ff];
plots = DeleteCases[plots, Line[_?(Length[#] < 3 &)], Infinity];
numlines = Array[Length@Cases[plots[[#]], Line[_], Infinity] &,
Length@ff];
(* Plot functions together for annotation plot *)
plot = ListLinePlot[#@spec & /@ ff];
plot = DeleteCases[plot, Line[_?(Length[#] < 3 &)], Infinity];
lbl = Flatten@Array[ConstantArray[ToString@ff[[#]],
numlines[[#]]] &, Length@ff];
(* Line positions to substitute with buttons *)
linepos = Position[plot, Line, Infinity];
Clear[line];
(* Copy all the lines to line[n] *)
Array[(line[#] = plot[[Sequence @@ Most@linepos[[#]]]]) &,
Total@numlines];
(* Button function *)
AddLabel[label_] := (AppendTo[plot[[1]],
Inset[Framed[label, Background -> White], pt]];
(* Remove buttons for final plain plot *)
plainplot = plot;
bpos = Position[plainplot, Button, Infinity];
Array[(plainplot[[Sequence @@ Most@bpos[[#]]]] =
plainplot[[Sequence @@ Append[Most@bpos[[#]], 1]]]) &,
Length@bpos]);
(* Substitute all the lines with line buttons *)
Array[(plot[[Sequence @@ Most@linepos[[#]]]] = Button[line[#],
AddLabel[lbl[[#]]]]) &, Total@numlines];
Dynamic[EventHandler[plot,
"MouseDown" :> (pt = MousePosition["Graphics"])]]
ff={Sin,Cos,Tan,Cot};
等级=范围[0.1,10,0.1];
(*单独打印函数以获得行计数*)
plots=Array[ListLinePlot[ff[#]/@spec]&,Length@ff];
plots=DeleteCases[plots,Line[#](长度[#]<3&]),无穷大];
numlines=数组[Length@Cases[plots[#]],Line[#],Infinity]&,
Length@ff];
(*用于注释打印的打印函数*)
plot=ListLinePlot[#@spec&/@ff];
plot=DeleteCases[plot,Line[#](长度[#]<3&]),无穷大];
lbl=Flatten@Array[君士坦塔雷[ToString@ff[[#]],
numlines[#]]&,Length@ff];
(*用按钮替换的行位置*)
linepos=位置[绘图、直线、无限];
清晰[线条];
(*将所有行复制到第[n]*行)
数组[(线[#]=绘图[[序列@@Most@linepos[[#]]]]) &,
Total@numlines];
(*按钮功能*)
AddLabel[label_3;]:=(附在[plot[[1]]之后,
插入[带边框[标签,背景->白色],pt]];
(*删除最终平面打印的按钮*)
平面图=平面图;
bpos=位置[平面图,按钮,无限];
数组[(平面图[[序列@@Most@bpos[[#]]]] =
平面图[[Sequence@@Append][Most@bpos[[#]], 1]]]) &,
Length@bpos]);
(*将所有行替换为行按钮*)
数组[(绘图[[序列@@Most@linepos[[#]]]=按钮[行[#]],
添加标签[lbl[#]]]&,Total@numlines];
动态[EventHandler]绘图,
“鼠标向下”:>(pt=MousePosition[“Graphics”])]]
这是它的样子。注释后,可以找到设置为“plainplot”变量的普通图形对象
年,出现了
网格
和绘图标记
之间相互作用的问题。当时我向WRI报告了这一情况,技术支持部门将其转发给开发小组进行查看。希望它能在下一个版本中得到修复。我很好奇为什么有些网格选项有效,而许多其他选项无效。至于你的第三个问题,你可能想看看我在这里使用的图表:。这涉及到手动注释(可以使其半自动工作)。我觉得最终的结果在视觉上比其他方法更令人愉悦。非常有趣的展示想法!对于工具提示来说,这是一个很好的选择(特别是当线条以某种方式高亮显示时,例如,它将变为粗体-我们不需要单击它,只需将鼠标放在上面即可!)。多谢各位+1非常好的主意,但是,它类似于工具提示,如果您需要打印绘图,它往往是无用的。不过对于演示来说,thast是一种很好的方式。@Markus-我添加了一个更完整的示例,它显示了