7
$\begingroup$

When I do a plot like this

ListPlot[
  {Style[{1, 2}, Red],
   Style[{2, 3}, Blue], 
   Style[{3, 4}, Green]}
 ]

under the colored points, there are duplicates with automatic Style. Indeed if you set Opacity differently than 1 you will the copy on the background

ListPlot[
  {Style[{1, 2}, Red],
   Style[{2, 3}, Blue, AbsolutePointSize[50], Opacity[0.5]],
   Style[{3, 4}, Green]}
 ]

enter image description here

How to solve it? Thank you

$\endgroup$
5
  • 2
    $\begingroup$ maybe lp=ListPlot[{Style[{1, 2}, Red, Opacity[.3], AbsolutePointSize[10]], Style[{2, 3}, Blue, Opacity[.3], AbsolutePointSize[10]], Style[{3, 4}, Green, Opacity[.3], AbsolutePointSize[10]]}] shows the issue more visibly. And, plt[[1]] clearly shows points are duplicated. Looks like a bug. $\endgroup$
    – kglr
    Nov 20, 2023 at 16:35
  • $\begingroup$ Actually, the issue is independent of Style wrapper. As ListPlot[{{{1, 2}}, {{2, 3}}, {{3, 4}, {4, 4}}, { {4, 5}, {5, 6}, {6, 7}}}][[1]] shows if a sublist contains a single point that point is repeated. $\endgroup$
    – kglr
    Nov 20, 2023 at 16:42
  • 1
    $\begingroup$ @kglr Easier to do Cases[Normal@plt, _Point, Infinity], if your plot is called plt, and the result is {Point[{{1., 2.}, {1., 2.}}], Point[{{2., 3.}, {2., 3.}}], Point[{{3., 4.}, {4., 4.}}], Point[{{4., 5.}, {5., 6.}, {6., 7.}}]}. Each of the single-point lists is repeated, whereas the multiple-point lists aren't. Weird. $\endgroup$
    – march
    Nov 20, 2023 at 16:45
  • 1
    $\begingroup$ weirder yet, check: ListPlot[{{{1, 2}}, Button[{2, 3}, Print[{2, 3}]], {{3, 4}, {3, 5}}, { {4, 5}, {5, 6}, {6, 7}}}][[1]] $\endgroup$
    – kglr
    Nov 20, 2023 at 16:46
  • $\begingroup$ @kglr Weird. I'm leaning towards classifying this as a bug, I think, but I'm not entirely sure: there could be some reason for this duplication of points in certain edge cases of ListPlot? It'd be nice if we could get some input from Mathematica employees. $\endgroup$
    – march
    Nov 20, 2023 at 19:08

1 Answer 1

5
$\begingroup$
$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global`*"]

data = {{1, 2}, {2, 3}, {3, 4}};

style = {Red, Directive[Opacity[0.2, Blue], AbsolutePointSize[50]], Green};

Make each data point a separate list.

ListPlot[List /@ data, PlotStyle -> style]

enter image description here

$\endgroup$
1
  • 3
    $\begingroup$ This is definitely a kluge that fixes the issue, so +1, but the repeated points are still there: Cases[Normal@plt, _Point, Infinity] (where plt is the plot) yields {Point[{{1., 2.}, {1., 2.}}], Point[{{2., 3.}, {2., 3.}}], Point[{{3., 4.}, {3., 4.}}]}. It works because it applies the same style to points in the same list, but the processing that goes on under the hood to create repeated points is still there and is weird. $\endgroup$
    – march
    Nov 20, 2023 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.