Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font family and color in guide.annotation #1323

Closed
IgorDouven opened this issue Sep 30, 2019 · 6 comments
Closed

font family and color in guide.annotation #1323

IgorDouven opened this issue Sep 30, 2019 · 6 comments

Comments

@IgorDouven
Copy link

I'm using Guide.annotation to add some text to a plot. As far as I can see, both the font family is different from the one Gadfly uses by default and also the color of the font is different (black instead of gray). I tried correcting the former by using font("Helvetica Neue"), but that doesn't seem to do anything. And I wasn't able to find out how I can change the font color (if that can be done at all; changing the font size of the annotation works fine). I'd be grateful for any advice.

@Mattriks
Copy link
Member

Mattriks commented Sep 30, 2019

Gadfly plots are drawn using the graphics package Compose.jl.
There are some examples of text in Compose here and here. Also in the Gadfly docs for Geom.abline
(p1 uses Guide.annotation).

The font() property should work, assuming that font is available. Compose font defaults:
https://github.com/GiovineItalia/Compose.jl/blob/a081070de98b7c5d46bc4a0aaf19426a71489b8d/src/Compose.jl#L119.

Gadfly font defaults:

const title_font_desc = "'PT Sans','Helvetica Neue','Helvetica',sans-serif"
.

@IgorDouven
Copy link
Author

IgorDouven commented Sep 30, 2019 via email

@Mattriks
Copy link
Member

For Gadfly, the text properties (including color) for plot labels are found here. Does that solve "not matching the color of the other labels"? If not, please provide example code of what you are doing.

@IgorDouven
Copy link
Author

Well, I could of course change the color of the "other" labels to black. Then the color would match the labels generated via compose. But then they would no longer match with the colors of the labels in all the other figures in the paper. (Of course, I could change them to black as well, but ...)

I don't have any special use case in mind. A MWE of what I'm doing is this:

using Gadfly, Compose

xcoords=rand(50)
ycoords=rand(50)
cols=rand(50)

Gadfly.plot(x=xcoords, y=ycoords, color=cols, Geom.point, Guide.title("Title"),
    Guide.annotation(compose(context(), Compose.text(0.4115, 0.89, "XXX"), fontsize(10pt), font("Helvetica-Neue"))))

The label XXX appears in a darker font than the other ones.

@Mattriks
Copy link
Member

Mattriks commented Oct 1, 2019

In this example, I've changed the font color of the Compose.text to Gadfly's major_label_font color.

using Colors
p1 = plot(x=xcoords, y=ycoords, color=cols, Geom.point, Guide.title("Title"),
    Guide.annotation(compose(context(), Compose.text(0.4115, 0.89, "XXX"), fontsize(10pt),
            font("Helvetica-Neue"), fill("black"), stroke(nothing)) ))
p2 = plot(x=xcoords, y=ycoords, color=cols, Geom.point, Guide.title("Title"),
    Guide.annotation(compose(context(), Compose.text(0.4115, 0.89, "XXX"), fontsize(10pt),
            font("Helvetica-Neue"), fill(colorant"#564a55"), stroke(nothing)) ))
hstack(p1, p2)

Does that help?

@IgorDouven
Copy link
Author

IgorDouven commented Oct 1, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants