GNU Octave DPI plot size troubleshooting

2 minute read

Related: GNU Octave set defaults


If GNU Octave plot fonts are too small or the lines are too thin in GNU Octave plotting, here’s some steps to take to fix that. Typically the first of these methods will be adequate, the others are for reference.

Backends

Note that Octave has three graphics “toolkits” or “backends”, listed here from worst to best:

  1. GNUplot (old, not many features)
  2. FTLK (soft deprecation)
  3. QT (best support and graphics)

Octave will try to use the best option QT first, then FTLK, and finally GNUplot.

If you don’t want the graphical IDE, start Octave with octave -no-gui instead of octave-cli. Using octave-cli disables the QT backend!

Default plot settings

These settings work for ftlk and qt backends only, NOT gnuplot!

I avoid setting font sizes in the program itself. Other people have different resolutions and PPI, and putting your particular computer display tweaks in your program code may make your plots look awful on other computers.

The “correct” way to scale plot fonts is thus to change your system defaults. Add this to ~/.octaverc instead of startup.m so that you don’t disturb Matlab’s plotting defaults.

set(0, "defaulttextfontsize", 24)  % title 
set(0, "defaultaxesfontsize", 16)  % axes labels

set(0, "defaulttextfontname", "Courier")
set(0, "defaultaxesfontname", "Courier")

set(0, "defaultlinelinewidth", 2)

adjust 16 to produce the most appealing text labels in:

  • axes tick labels
  • legend key
  • title text

defaultline is the root category for lines, so defaultlinelinewidth is not a typo.

Other methods

These methods are not normally needed, but are for reference.

PPI adjustments

  1. Does Octave know your laptop/monitor PPI? (Note, DPI has been overloaded to mean PPI by many OEMs). Find your PPI by Internet search or spec sheet.
    get(0, 'screenpixelsperinch')
    

    If Octave’s PPI estimate is too small, this is probably why your plot text is too small–Octave thinks your resolution is much less than it really is.

  2. Try changing system DPI scaling. On Ubuntu, try Gnome Tweak Tool → Fonts → Scaling Factor
  3. Octave Settings
    • → General → Interface → Icon Size: large
    • → Editor Styles → Octave: default
    • → Terminal → Font Size

Graphics Toolkit

You can also try changing the graphics toolkit. Usually QT is the best, most modern, as it’s QT5 (most likely).

  1. which graphics toolkits are available? From Octave:
    available_graphics_toolkits()
    

    fltk gnuplot qt

  2. which graphics toolkit are you using?
    graphics_toolkit()
    

    qt

  3. try another graphics toolkit to see if font sizes are better.
    graphics_toolkit('fltk')
    figure()
    plot([1,2,3,4]); title('hi there')
    

    be sure to open a new figure when trying different graphics toolkits.

Notes

GNU Octave default settings docs

Leave a comment