I am currently working with figures that I save in SVG format, in order to include them into a HTML presentation. I'm looking for consistency in terms of fonts, line sizes etc .. across the presentation.
Hence, I need to scale all my figures of a factor 2 in width compared to the default matplotlib
params.
For now, I am relying on an external python lib, svgutils
:
import matplotlib.pyplot as plt
import svgutils.transform as sg
figname = 'test.svg'
fig = plt.figure()
fig.savefig(figname)
fig = sg.fromfile(figname)
newsize = ['{}pt'.format(2 * float(i.replace('pt', ''))) for i in fig.get_size()]
fig.set_size(newsize)
fig.save(figname)
but this is a small project and I am not sure it will be maintained through time, so I'd like to do it only with matplotlib
.
If I only modify the figsize
, all other elements (i.e lines) do not increase in size. Is there a way to scale all parameters? Or should I go over each element defined in the rcParams
and scale them appropriately? That looks rather long to do ...
EDIT: Note that changing the DPI (as suggested here) will not work, as SVG objects do not have associated DPI, unlike raster formats (i.e png, jpeg, etc ..).
rcParams
.rcParams
, or use a scaling factor, as follows.large'
, which will be replaced with the corresponding numeric value, and then scaled.matplotlib.rcParams
python 3.12.0
,matplotlib 3.8.0
Printed Output
scale_factor = 2
scale_factor = 1
Example images are png because svg is not supported on StackOverflow.