Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get high-resolution plots in a Jupyter notebook using the R kernel?

Using SVG in a Jupyter notebook with R kernel mangles the text. See here and here. The workaround is to use PNG. It's a bit blurry. In Python, you can ask the PNG renderer to use more dots per inch with

 InlineBackend.figure_format = 'retina'

See for example trick 15 here.

How can I get higher resolution plots using the R kernel? SVG workaround? PNG renderer settings?

Edit: I'm using ggplot in R.

Edit 2: I found repr.plot defaults here, including res, which looks to be dots per inch (dpi). However, when I raise the res from 120 to 300, the plot gets bigger, despite me setting height and width.

Edit 3: I filed this issue. There are suggestions for how to fix it in the code, but no workarounds.

like image 456
dfrankow Avatar asked Jan 20 '26 03:01

dfrankow


1 Answers

I have recently discover that packages : plotly can work well on creating ggplot images

try the plot_ly() function to save png pics

here is a demo using plot_ly

hope this can help!

like image 133
GMfatcat Avatar answered Jan 21 '26 18:01

GMfatcat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!