1

I am using the tikzviolinplots to locally compile pdf figures that I upload to my main document on overleaf. I need them to have the following properties

  1. Each should have identical dimensions
  2. The font size in the figures should match the body text in my main document

My problem is that the externalized figures often have differing heights and/or widths.

My problem is similar to this question but I think has an additional complication in that the tikviolinplot package uses one axis environment for every individual violin.

Here's an example. I use this type of script for each figure I have. What I need is that if the below file produces fig22.pdf and a similar one produces fig23.pdf via tikzexternalize, both of the pdfs should have the same dimensions and aspect ratio.

\documentclass[10pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{subcaption}
% Package for si units
\usepackage{siunitx}

% Packages for making pictures with LaTeX
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,fit,backgrounds,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{tikzviolinplots}
\usepgfplotslibrary{external}
\tikzexternalize
\usepackage{minted}
\usemintedstyle{gruvbox-light}
\usepackage{scontents}

% Package to superimpose text on an image
\usepackage[percent]{overpic}

\begin{document}
        \begin{figure}[ht!]
            \centering
            \pgfplotsset{height=6cm,width=8cm}
             \begin{tikzpicture}
                  \violinsetoptions[
                        averages,
                        data points,
                        scaled  
                    ]{
                        xmin=0,xmax=4,
                        ymin=0,ymax=1,
                        xlabel style={
                        yshift = {-3*width("a")}
                        },
                        ymajorgrids=true,
                        ylabel={ylabel text},
                    }
            \violinplot[%
            index=col1,
            relative position=1,
            color=red,
            label={COL 1},
            col sep=comma,
            ]{fig22.csv}
            \violinplot[%
            index=col2,
            relative position=2,
            color=blue,
            label={COL 2},
            col sep=comma,
            ]{fig22.csv}
            \violinplot[%
            index=col3,
            relative position=3,
            color=purple,
            label={COL 3},
            col sep=comma,
            ]{fig22.csv}
        \end{tikzpicture}
    \end{figure}
    
\end{document}

The line \pgfplotsset{height=6cm,width=8cm} is motivated by various attempts I've made to follow the directions of the tikzviolinpackage for figure sizing. In the linked document, they note that figure and font scaling is one of the package limitations.

EDIT: example csv file for fig22

index,col1,col2,col3
0,0.0,0.044,0.0
1,0.5,0.339,0.38
2,0.3333,0.35,0.54667
3,0.4575,0.417,0.7085
4,0.6,0.5884,0.8316
5,0.83333,0.732333,0.764333
6,0.856857,0.752286,0.835143
7,0.94225,0.8675,0.87675
8,1.0,0.931778,0.917556
9,1.0,1.0,1.0

example csv file for fig23

index,col1,col2,col3
0,-0.49,-0.55,-0.45
1,0.1,0.01,0.02
2,0.3333,0.35,0.54667
3,0.4575,0.417,0.7085
4,0.6,0.5884,0.8316
5,0.83333,0.732333,0.764333
6,0.856857,0.752286,0.835143
7,0.94225,0.8675,0.87675
8,1.0,0.931778,0.917556
9,1.0,1.0,1.0

This is not my actual data, but I think should convey the problem. With the type of tex file I have, the resulting externalized fig22.pdf will be shorter than fig23.pdf. I think it is because the yrange for fig22 is [0,1] and the yrange for fig23 is [-.5,1]

7
  • Welcome! Thanks for providing some code, but unfortunately nobody will be able to compile this without the data file, so it may be hard for people to reproduce the problem. I'm also a bit unclear what exactly you want to happen: how should the images be changed? If they are scaled, you will obviously get non-matching fonts. Moreover, if their original aspect-ratios differ, you'll get distortion. You could put them on a larger background, of course, but then it would be easier to just put them in boxes in the document. So what would you ideally like to happen here?
    – cfr
    Commented Sep 27, 2023 at 17:36
  • I'm not able to test if the two sample csvs I edited into the question cause what I say at the moment, but I think they help convey a case of my problem (see edit). The necessary change to the output I'm getting is that the non text elements of the plot in fig22 are stretched so that the figure is taller, but font size is unchanged and text doesn't look weird (too much space between letters, letters too small, letters stretched). Commented Sep 27, 2023 at 21:34
  • Thanks for editing. Did you see tex.stackexchange.com/questions/433471/…? (Note that I don't know if it is helpful or not - it just seems potentially so at first glance.)
    – cfr
    Commented Sep 27, 2023 at 23:17
  • Your method seems to be what the docs suggest. Perhaps it would be worth raising the issue at github.com/pedro-callil/tikzviolinplots?
    – cfr
    Commented Sep 27, 2023 at 23:50
  • If I can't figure it out today I'll make a git issue. Using the link you sent (thanks!) I found that if I put scale only axis=true and axis equal = true into pgfplotsset, the resulting figures are not ideal. The main problem is that my y axis limits are ignored. Secondarily, the widths differ by 5 pixels. If I just use scale only axis=true, the y axis limits are respected but the widths still differ by 5 pixels. Using the axis equal = true option alone gives the worst result, with the image having lots of white space padding and the x axis labels overlapping. Commented Sep 28, 2023 at 13:54

0

You must log in to answer this question.

Browse other questions tagged .