3 ms·
Wow, this sounds really cool! Out of curiosity, did you get bad results with the pure PGF backend? (And can you link to your script by any chance?) I'm always a
by PythonNut 5y ago
Wow, this sounds really cool! Out of curiosity, did you get bad results with the pure PGF backend? (And can you link to your script by any chance?) I'm always amazed that including matplotlib plots in LaTeX documents is so fraught since it's such common use case.
Also I read that matplotlib 3.5 has some sort of improved support for type 42 subsetting. I haven't had a chance to try it out yet but this could be a welcome improvement!
- jamiedamien 5y agoOh didn't know about the improved type 42 font support in the new matplotlib! That's good to know and I should check it out. And good point, the PGF works just as well (results should be identical), but since all the plot information has to be compiled by latex, it ends up ballooning the compilation time of the tex doc and the matplotlib PGF page suggests that you can run into memory issues as well. I was doing this for a thesis with 50+ plots and so still wanted compilation to be fast. I've suggested this as an improvement to matplotlib, but unlikely to be merged since maybe it's a bit hacky (although it's very similar to what Inkscape's export to LaTeX option does): https://github.com/matplotlib/matplotlib/issues/22297 https://github.com/matplotlib/matplotlib/issues/22297 (the backend file can be found here: https://github.com/matplotlib/matplotlib/files/7921801/backend_pgftext.txt https://github.com/matplotlib/matplotlib/files/7921801/backe...) And the gs script is below: #!/bin/bash set -e set -o pipefail if [ -z $1 ]; then echo "Supply input output" exit 1; fi if [ -z $2 ]; then outfile="$(basename ${1} .pdf)-small.pdf" if [ -f $outfile ]; then echo "WARNING ${outfile} already exists." echo "Supply input output" exit 1; fi else outfile="${2}" fi gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -dQUIET -dDetectDuplicateImages=true -r150 -sOutputFile="${outfile}" "${1}" pre_b=$(wc -c "${1}" | cut -d' ' -f1) post_b=$(wc -c "${outfile}" | cut -d' ' -f1) if (( $pre_b <= $post_b )); then echo "Original is smaller ($pre_b -> $post_b). copying..." cp "${1}" "${outfile}" fi