Guiraldelli
Guiraldelli

Reputation: 532

How to put symbols in X-axis ticks in Julia's Gadfly?

I would like to plot a (e.g. sine) curve with X-axis on -pi/2, 0, pi/2, but I wanted:

  1. to have ticks just in these points;
  2. to have the symbol of pi (i.e. π, π/2, etc...) in the tick, not the text "pi", "pi/2", etc...

How is it possible with Julia's Gadfly?

Upvotes: 4

Views: 1140

Answers (2)

Abhijith
Abhijith

Reputation: 1208

To have ticks at any points. e.x, at π/2 and π try this,

julia>plot([sin,cos],0,6, Stat.xticks(ticks=[π/2,π]))

enter image description here

It is not possible to have symbols like π as ticks.

Upvotes: 1

James Kyle
James Kyle

Reputation: 464

Julia supports utf encodings, so to render the pi symbol you'd do this

pi = char(960)

With 960 being the integer code for pi. When I used this directly in the Gadfly plot legend, it was rendered as a color bar on max range 960 (no idea why). But I got around that by using @sprintf macro.

Final solution:

using Gadfly
using DataFrames

Gadfly.set_default_plot_size(20cm, 12cm)
pi = @sprintf("%s", char(960))
df1 = DataFrame(x=rand(100), y=rand(100), label=s)
plot(df1, x="x", y="y", color="label")

enter image description here

Upvotes: 0

Related Questions