Modify axis options when using Plots.jl with pgfplotsx backend

lcm
Mon, 14 Oct 2024 14:46:13 +0000
Visualization

I am using Plots.jl with the pgfplotsx() backend for emitting .tikz files. Together with the tikzscale LaTeX package this makes for nice plots for a TeX document.
However, in the emitted plots there are a lot of options on each axis. Amongst them are height and width as well as font={{..}} for the title, legend, labels and ticks. These all interfere with tikzscale, as the width will be set only when including the file and the font size should match the surrounding document style.

Is there a way to modify or delete these options before any PGFPlotsX code starts assembling the .tikz file? As I understand they are defaults being passed from Plots.jl. Suppose I have a single axis created by p = plot(...), then p.subplots[1].attr holds all these options even before PGFPlotsX generated the plot. Deleting them from this Dict leads to errors though:

julia> delete!(p.subplots[1].attr, :titlefontsize);

julia> p
Error showing value of type Plots.Plot{Plots.PGFPlotsXBackend}:
ERROR: KeyError: key :titlefontsize not found

is there a way to remove some options? My current alternative would be some sed command or something to remove it from the .tikz file after generation.

I know this could be easily controlled when using PGFPlotsX.jl directly, however I am changing the plots regularily and like being able to switch back and forth between gr() for plot modifications and pgfplotsx() for checking how it looks in the final document.

3 posts - 1 participant