4
$\begingroup$

Let us assume I have several sets of data points with labels, e.g.:

alabels = Array["a" ~~ ToString[#] &, 10];
blabels = Array["b" ~~ ToString[#] &, 10];
avalues = RandomVariate[NormalDistribution[1, 1], {10, 2}];
bvalues = RandomVariate[NormalDistribution[11, 1], {10, 2}];
aassoc = AssociationThread[alabels -> avalues];
bassoc = AssociationThread[blabels -> bvalues];

Assuming the above, ListPlot[aassoc] works, as does ListPlot[bassoc], while ListPlot[{aassoc, bassoc}] yields a Callout:copos: {Automatic} is not a valid position for the placement of callouts. error message. Firstly, I'd like to know why the latter does not work, and secondly, how to get it to work. Thanks!

$\endgroup$
1
  • $\begingroup$ Show[ListPlot /@ {aassoc, bassoc}, PlotRange -> All] $\endgroup$
    – Bob Hanlon
    Nov 21 at 1:11

3 Answers 3

4
$\begingroup$

Building up on Bob Hanlon's comment:

alabels = Array["a" ~~ ToString[#] &, 10];
blabels = Array["b" ~~ ToString[#] &, 10];
avalues = RandomVariate[NormalDistribution[1, 1], {10, 2}];
bvalues = RandomVariate[NormalDistribution[11, 1], {10, 2}];
aassoc = AssociationThread[alabels -> avalues];
bassoc = AssociationThread[blabels -> bvalues];

center = {Values@aassoc, Values@bassoc} // Map[Mean] // Mean
MapThread[
  ListPlot[#1, PlotStyle -> #2, Background -> None] &, {{aassoc, 
    bassoc}, {Red, Blue}}] //
 Show[#, PlotRange -> All, AxesOrigin -> center] &

enter image description here

$\endgroup$
4
$\begingroup$

Apparently, ListPlot cannot handle list of associations in the first argument. Using the option LabelingFunction -> None, we suppress the call to Callout and avoid the error message. In this case, only the first association is rendered:

ListPlot[{aassoc, bassoc}, LabelingFunction -> None]

enter image description here

Work-arounds

1. Pre-process input associations into a single association

Wrap values of each association with desired Style and Join to get a single association:

abassoc = Apply[Join]@
  MapThread[{x, y} |-> Map[Style[#, y] &] @ x] @
  {{aassoc, bassoc}, {Red, Blue}}; 

 ListPlot[abassoc, 
 PlotLegends -> PointLegend[{Red, Blue}, {"A", "B"}]]

enter image description here

2. Use BubbleChart

 {aassoc2,bassoc2} = Map[Map@Append[1]]@{aassoc, bassoc};

BubbleChart[{aassoc2,bassoc2}, 
 BubbleSizes -> {.01, .01}, 
 ChartLabels -> Automatic, 
 LabelingFunction -> Callout,
 ChartElementFunction -> "Point", 
 ChartBaseStyle -> PointSize[Medium],
 ChartLegends -> {"A", "B"}, 
 LegendAppearance -> {LegendMarkers -> "Bubble"},
 PlotRangePadding -> Scaled[.1]]

enter image description here

$\endgroup$
3
$\begingroup$

A minimalistic approach:

ListPlot[<|aassoc, bassoc|>,
 Frame -> True,
 PlotRangePadding -> 2]

enter image description here

$\endgroup$

Your Answer

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

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