在 Mathematica 的 ListPlot 中指定点样式

发布于 2024-12-02 14:21:20 字数 478 浏览 2 评论 0原文

考虑到

dacount = {{0, 69}, {1, 122}, {2, 98}, {3, 122}, {4, 69}}

ListPlot[dacount, AxesOrigin -> {-1, 0}, 
         PlotMarkers ->Automatic
         PlotStyle-> Lighter[Red, #] & /@ Range[0.5, 1, 0.1],
         Filling -> Axis, FillingStyle -> Opacity[0.8], 
         PlotRange -> {{-1, 4.5}, {0, 192}}]

在此处输入图像描述

我希望每个点都采用不同的红色阴影。 但我无法理解如何为我尝试设置为不同列表的点设置样式。

Considering

dacount = {{0, 69}, {1, 122}, {2, 98}, {3, 122}, {4, 69}}

ListPlot[dacount, AxesOrigin -> {-1, 0}, 
         PlotMarkers ->Automatic
         PlotStyle-> Lighter[Red, #] & /@ Range[0.5, 1, 0.1],
         Filling -> Axis, FillingStyle -> Opacity[0.8], 
         PlotRange -> {{-1, 4.5}, {0, 192}}]

enter image description here

My hope there was for each point to take a different shade of red.
But I can`t understand how to have a style for point which I tried to set as different list.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下壹個目標 2024-12-09 14:21:20

在原始代码中,PlotStyle 选项不会影响标记符号,因此您可以将其忽略。相反,将 PlotMarkers 选项更改为以下内容:

PlotMarkers ->  With[{markerSize =  0.04}, 
 {Graphics[{Lighter[Red, #], Disk[]}], markerSize} & /@ Range[0.5, 1, 0.1]]

在将列表 dacount 替换为以下内容之前,这还不会达到预期的效果:

Map[List, dacount]

通过以这种方式增加点列表的深度,每个点都会从列在 PlotMarkers 中。所以最终的代码是:

ListPlot[Map[List, dacount], AxesOrigin -> {-1, 0}, 
 PlotMarkers -> 
  With[{markerSize = 
     0.04}, {Graphics[{Lighter[Red, #], Disk[]}], markerSize} & /@ 
    Range[0.5, 1, 0.1]], Filling -> Axis, 
 FillingStyle -> Opacity[0.8], PlotRange -> {{-1, 4.5}, {0, 192}}]

在此处输入图像描述

In your original code, the PlotStyle option won't affect the marker symbols, so you can leave it out. Instead, change your PlotMarkers option to the following:

PlotMarkers ->  With[{markerSize =  0.04}, 
 {Graphics[{Lighter[Red, #], Disk[]}], markerSize} & /@ Range[0.5, 1, 0.1]]

This will not yet have the desired effect until you replace the list dacount by:

Map[List, dacount]

By increasing the depth of the point list in this way, each point is assigned a marker style of its own from the list in PlotMarkers. So the final code is:

ListPlot[Map[List, dacount], AxesOrigin -> {-1, 0}, 
 PlotMarkers -> 
  With[{markerSize = 
     0.04}, {Graphics[{Lighter[Red, #], Disk[]}], markerSize} & /@ 
    Range[0.5, 1, 0.1]], Filling -> Axis, 
 FillingStyle -> Opacity[0.8], PlotRange -> {{-1, 4.5}, {0, 192}}]

enter image description here

无妨# 2024-12-09 14:21:20

您还可以通过以下方式执行此操作:

xMax = Max@dacount[[All, 1]];
Show@(ListPlot[{#}, AxesOrigin -> {-1, 0}, PlotMarkers -> Automatic, 
     PlotStyle -> (RGBColor[{(#[[1]] + 5)/(xMax + 5), 0, 0}]), 
     Filling -> Axis, FillingStyle -> Opacity[0.8], 
     PlotRange -> {{-1, 4.5}, {0, 192}}] & /@ dacount)

在此处输入图像描述

这将绘制 dacount 中的每个点单独并根据 x 值为其分配红色阴影。然后将这些图与 Show 结合起来。

我任意选择了不同色调的缩放和偏移。你可以选择任何你想要的,只要你确保最大值是1。

You can also do it the following way:

xMax = Max@dacount[[All, 1]];
Show@(ListPlot[{#}, AxesOrigin -> {-1, 0}, PlotMarkers -> Automatic, 
     PlotStyle -> (RGBColor[{(#[[1]] + 5)/(xMax + 5), 0, 0}]), 
     Filling -> Axis, FillingStyle -> Opacity[0.8], 
     PlotRange -> {{-1, 4.5}, {0, 192}}] & /@ dacount)

enter image description here

This plots each point in dacount individually and assigns it a shade of red depending on the x value. The plots are then combined with Show.

I've arbitrarily chosen a scaling and offset for the different shades. You can choose whatever you want, as long as you ensure that the max value is 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文