Mathematica 中的 ListPlot、ErrorListPlot 中的单个点着色
我可以通过执行类似
ListLinePlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
的操作来获得彩色 ListLinePlot
但是,如帮助所示文件(“ColorFunction
需要至少一个数据集加入
”),如果我执行等效的
ListPlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
我的所有点都是蓝色的。有没有一种好的方法可以让 ColorFunction
与 Joined ->; 一起用于
ListPlot
?假的?
也就是说,有没有更好的方法来获得类似的东西
ListPlot[
List /@ Transpose[{Range[(680 - 420)/20 + 1], Range[420, 680, 20]}],
PlotMarkers -> ({Graphics[{#, Disk[]}], 0.05} & /@ ColorData["VisibleSpectrum"] /@ Range[420, 680, 20])
]
?
(另外,有没有人能解释为什么 Mathematica 需要加入 - > True
以便使用 ColorFunction
?)
编辑:我也在寻找一种方法来使用 ErrorListPlot
进行类似的着色ErrorBarPlots
包。
I can get a colored ListLinePlot
by doing something like
ListLinePlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
However, as indicated by the help file ("ColorFunction
requires at least one dataset to be Joined
"), if I do the equivalent
ListPlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
all my points are blue. Is there a nice way to get ColorFunction
to work for ListPlot
with Joined -> False
?
That is, is there a nicer way to get something like
ListPlot[
List /@ Transpose[{Range[(680 - 420)/20 + 1], Range[420, 680, 20]}],
PlotMarkers -> ({Graphics[{#, Disk[]}], 0.05} & /@ ColorData["VisibleSpectrum"] /@ Range[420, 680, 20])
]
?
(Also, does anyone have an explanation of why Mathematica requires Joined -> True
in order to make use of ColorFunction
?)
Edit: I'm also looking for a way to do a similar coloring with ErrorListPlot
in the ErrorBarPlots
package.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,Joined->True 绘制一条 Line[],可以为每个包含点指定 VertexColors。我假设在设置 Joined->False 时对点执行相同的操作会导致它不起作用的情况。不过,在您的情况下,Line[] 和 Point[] 的工作原理几乎相同。 又是什么呢?
那么
顺便说一句,如果您仅使用 ListLinePlot,则唯一的 Line[] 指令产生的是您的数据中的数据,即使您有更多数据集和 {x,y} 坐标,这也应该有效
The problem is, that Joined->True draws a Line[] which can be given VertexColors for each containing point. I assume doing the same for the points when setting Joined->False leads to situations where it does not work. Nevertheless, Line[] and Point[] work pretty much the same in your case. So what is about
And, by the way, if your using a ListLinePlot only, where the only Line[] directives arising are the one from your data, this should work even if you have more datasets and {x,y} coordinates
您可以使用
DiscretePlot
:如果您要绘制 x,y 点列表,它变得有点棘手:
DiscretePlot
确实看起来很奇怪让您对点进行不同的着色,而ListPlot
不会。我确信这一定与实现细节有关,但我想不出为什么会出现这种情况。You can use
DiscretePlot
:If you're plotting a list of x,y points, it gets a little trickier:
It does seem rather odd that
DiscretePlot
will let you color the points differently whereasListPlot
won't. I'm sure it must have something to do with the implementation details, but I can't think of a reason why that would be the case.我在工作中也遇到了这个问题。我按以下方式为每个点分配颜色:
其中
c1
是第一个数据点的颜色,依此类推。颜色列表可以通过编程方式生成,例如这是结果。
这样做的优点方法如下。
ListPlot
代码不需要修改(例如,改为ListLinePlot
)。I came across this problem in my work too. I assign a colour to each point in the following manner:
where
c1
is the colour for the first data point, and so on. The colour list may be programmatically generated, egHere is the result.
The good points of this method are as follows.
ListPlot
code needs not be modified (eg, changed intoListLinePlot
).