Jeremy McNees
Jeremy McNees

Reputation: 787

Gadfly.jl Display Actual Values on Chart

I'm trying to determine if it's possible to display the underlying data points on a Gadfly chart. I know that I can display the labels associated with a particular point, but how can I show the actual values on the chart, itself?

For example, from the Gadfly documentation, let's say I have this chart:

plot(x=rand(10), y=rand(10))

How can I display the resulting values in the x and y vectors on the chart itself?

Upvotes: 2

Views: 329

Answers (2)

David P. Sanders
David P. Sanders

Reputation: 5325

Actually, it's easy to get a string representation, e.g. string(3).

How about the following:

using Gadfly

N = 10
xx = rand(1:10, N)  # N random integers between 1 and 10
yy = rand(1:10, N)

labels = map(string, zip(x,y))

plot(x=xx, y=yy, label=labels, Geom.label, Geom.point)

This gives something like the following:

points labelled by coordinates

Upvotes: 4

Jeremy McNees
Jeremy McNees

Reputation: 787

One way to do this is to feed the values into Gadfly via a labels string vector:

label_vec = ["4", "4", "7", "7", "9", "1", "8", "10", "11", "2"]

plot(x=rand(10), y=rand(10), Labels = label_vec, Geom.label)

It's a pain to parse ints/floats into strings though, it would be nice if you could feed them directly into Gadfly as ints/floats.

Does anyone have a better way?

Upvotes: 1

Related Questions