Message Boards Message Boards

0
|
2275 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How do I create a custom label for LabelingFunction?

Posted 2 years ago

How do I use LabelingFunction on a List of String Variables or a Function that generates String Variables? I want the List Plot to Display the individual elements of the List variable LabelString.

LabelString = Table[StringForm["Test # ``", LS], {LS, 1, 25}];

 ListPlot[Prime[Range[10]], LabelingFunction ->(LabelString@# &) , 
    ImageSize -> 900, Filling -> Axis, 
    PlotTheme -> "Web"]

Gives

LabelingFunction Result

2 Replies
Posted 2 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

You have at least two options here. First (read the documentation for ListPlot) you can do something like this:

ListPlot[{1.5, 1, 2.5, 3} -> {"a", "b", "c", "d"}]

So, pare your label list down to the right size and just use that form.

Or, you can build your own custom LabelingFunction, but it has to take the right arguments. The documentation for LabelingFunction describes the inputs:

each chart element should have a label given by f[value,index,lbls], where value is the data value associated with the element, index is its position in the nested list of datasets, and lbls is the list of relevant labels

In this description, index is in the form suitable for use by Extract. We'll need to add some structure to your LabelString list, because it's expecting 2D data. So, something like this would work:

LabelFun[_, idx_, _] := Extract[{LabelString}, idx]

Pass it to LabelingFunction like this:

ListPlot[Prime[Range[10]], LabelingFunction -> LabelFun, 
 ImageSize -> 900, Filling -> Axis, PlotTheme -> "Web"]
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract