Skip to content

Conversation

@casparvl
Copy link

@casparvl casparvl commented Sep 20, 2021

This PR partly solves IRkernel/IRkernel#604 .

As suggested in that issue, fonts for axes labels sometimes appear to have poor resolution. To resolve this, it is suggested in that issue to use the Cairo device, by setting options(bitmapType='Cairo') in the startup argv for the kernel (i.e. in the kernel.json).

This does indeed make sure that the Cairo device is used from that point onward. However, it will still use the default font. In my case that was a Helvetica, a (low-resolution) X11 font, and the resulting axes labels would still show the poor resolution.

The solution is to use a vector-type font, such as sans. The problem is that for png plot types with the Cairo device, the repr.plot.family is ignored.

This PR makes sure that the font family specified in repr.plot.family is indeed set to the Cairo devices.

I already suggested the change a long time ago but never found the time to make the change, test it, and PR it... In that thread, I proposed this approach to @flying-sheep who also considered it a good approach.

For me, with this PR, I can now do

options(repr.plot.width = 10, repr.plot.height = 8, repr.plot.res=96, repr.plot.family='FreeMono')

ggplot(iris) + geom_point(aes(Sepal.Width, Petal.Width)) + cowplot::theme_cowplot(
    font_size=25)

and get:
image
While with

options(repr.plot.family='LiberationMono')
ggplot(iris) + geom_point(aes(Sepal.Width, Petal.Width)) + cowplot::theme_cowplot(
    font_size=25)

I get
image

These samples clearly show that the repr.plot.family is now respected.

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

Successfully merging this pull request may close these issues.

2 participants