2
$\begingroup$

I have a set of data in an array; each element of the overall array is a list of the form $\{x, y, c\}$, where $c$ is a number representing a property of the data point $\{x, y\}$. I can plot these data pretty straightforwardly on a ListPlot:

RandomSeed[719];
data = RandomReal[{0, 1}, {100, 3}];
wrappeddata1 = Style[{#[[1]], #[[2]]}, ColorData["DarkRainbow"][#[[3]]]] & /@ data;
ListPlot[wrappeddata1, AspectRatio -> 1, ImageSize -> Large]

enter image description here

However, I need to differentiate between the data in a particular region of the plot (given by an inequality $f(x,y) < c$) and the data outside of this region. I can change the color of the data points easily enough; for example, I can color all points with $x^2 + y^2 < 1/4$ black:

wrappeddata2 = Style[{#[[1]], #[[2]]}, If[#[[1]]^2 + #[[2]]^2 < 1/4, Black, 
  ColorData["DarkRainbow"][#[[3]]]]] & /@ data;
ListPlot[wrappeddata2, AspectRatio -> 1, ImageSize -> Large]

enter image description here

What I would really like to do, though, is change the markers' shape according to their location, instead of changing their color. In other words, I'd like to turn every red dot into a red triangle (say) inside a given region, and leave all the other markers as is. If I split the data into two lists, though, I can't change the marker without losing the coloring; the command

ListPlot[GatherBy[wrappeddata1, #[[1, 1]]^2 + #[[1, 2]]^2 > 1/4 &], 
         AspectRatio -> 1, ImageSize -> Large]

yields something that's identical to the first plot, while

ListPlot[GatherBy[wrappeddata1, #[[1, 1]]^2 + #[[1, 2]]^2 > 1/4 &], 
         AspectRatio -> 1, ImageSize -> Large, PlotMarkers -> {"●", "×"}]

loses the coloring information:

enter image description here

(GatherBy also has the problem that it doesn't reliably sort the values according whether they're inside or outside the desired region, but that's a side issue and easily solved if necessary. I'm really more concerned with retaining the coloring while using different marker styles.)

$\endgroup$
1
$\begingroup$

Here is one way to do it.

SeedRandom[42]
data = RandomReal[{0, 1}, {100, 3}];

With[{c = 1/4},
  wrappedData =
    Style[
      {#[[1]], #[[2]]},
      If[(#[[1]]^2 + #[[2]]^2) < c, Black, Red]] & /@ data]];
Show[
  ListPlot[wrappedData, AspectRatio -> 1, ImageSize -> Large],
  Graphics[Circle[{0, 0}, 1/2]]]

red_black

I have use only red and black coloring to make the results clearer. But with

With[{c = 1/4},
  wrappedData =
    Style[
      {#[[1]], #[[2]]},
      If[(#[[1]]^2 + #[[2]]^2) < c, 
        Black, ColorData["DarkRainbow"][#[[3]]]]] & 
     /@ data];

you can have your rainbow coloring outside the circle of radius 1/2.

rainbow_black

To get different markers, abandoning ListPlot might be a good idea. Consider

With[{c = 1/4},
  markers =
    If[(#[[1]]^2 + #[[2]]^2) < c,
      Text[
        Style["■", 20, ColorData["DarkRainbow"][#[[3]]]], 
        {#[[1]], #[[2]]}],
      Text[
        Style["●", 13, ColorData["DarkRainbow"][#[[3]]]], 
        {#[[1]], #[[2]]}]] &
    /@ data];

Graphics[{markers, Circle[{0, 0}, 1/2, {0, 90 °}]},
  ImageSize -> Large, Frame -> True]

rainbow_markers

$\endgroup$
1
$\begingroup$

You could use BubbleChart

BubbleChart[
 GroupBy[data, #[[1]]^2 + #[[2]]^2 > 1/4 &] /. {a_, b_, c_} :> {a, b, 1},
 ChartLegends -> Automatic,
 ChartStyle -> {Blue, Red},
 ChartElements -> {Graphics[Disk[]], Graphics[Rectangle[]]}]

enter image description here

To preserve the original color scheme:

BubbleChart[
 GroupBy[data, #[[1]]^2 + #[[2]]^2 > 1/4 &],
 BubbleSizes -> {0.07, 0.07},
 ColorFunction -> (ColorData["DarkRainbow"][#3] &),
 ChartElements -> {Graphics[Disk[]], Graphics[{Rectangle[]}]}]

enter image description here

$\endgroup$
  • $\begingroup$ I haven't really looked into BubblePlot. I did want to retain the original color-coding both inside & outside the region, though. (Sorry if that wasn't clear from my question — I've edited it to be clearer.) Is it possible to do this with BubblePlot? $\endgroup$ – Michael Seifert Jul 21 '17 at 2:03
  • $\begingroup$ See updated answer $\endgroup$ – eldo Jul 21 '17 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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