0

I am not sure if my title gets through what I'm after, but basically I am using matlab2tikz to generate some plots for me and am wondering how you can do some modifications from outside the .tikz file.

e.g a .tikz from matlab2tikz will be like:

\begin{tikzpicture}
\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=1, xmax=511, xlabel={$\text{q (um}^\text{-}\text{1)}$},
ymin=0.5, ymax=1, ylabel={Normalized RMS error}]
\addplot [color=blue,solid,line width=1.0pt,forget plot]
table[row sep=crcr]{
1    -57.943745    \\
2    .more data
3    .more data
};
\end{axis}
\end{tikzpicture}%

I am importing and scaling the files in my document as follows (copied from Dimension too large from matlab2tikz, and aligning graph axis ):

\begin{table}[h!]  
     \begin{center}
     \begin{tabular}{ c  p{6cm}  p{6cm}  }
     \toprule
      A & B & C \\
      \cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}
      text              
      &     
      \scalebox{0.4}{\input{images/exp5nrmse.tikz}}
      \scalebox{0.4}{\input{images/exp5diff.tikz}}
      \scalebox{0.4}{\input{images/exp5diff.tikz}}]
      & 
      \scalebox{0.4}{\input{images/exp5nrmse.tikz}}
      \\ \bottomrule
      \end{tabular}
      \caption{DDM Results}
      \label{tbl:myLboro}
      \end{center}
\end{table}

Is it possible to change things like picture width, height, x and y label positions and things without having to edit the actual .tikz files. I ask because the presented code's graphs do not line up, and I would like to never have to touch the contents of the .tikz files to fix this issue. Picture of the problem below (the red lines I added in paint show the misalignment):

Misaligned graphs

Thanks for your time.

  • 1
    Regarding the width and height, you can do as mentioned in matlab2tikzs readme. In Matlab, use e.g. matlab2tikz('myfig.tex','width','\figwidth','height','\figheight'). This sets the width/height to the macros \figwidth/\figheight. In the LaTeX file, define lengths with these names, and use \setlength to change the lengths, as seen in e.g. http://tex.stackexchange.com/q/142980/586. That way you can also avoid using \scalebox. For your specific case, you could use a right aligned table column, that would make the plots lined up along their right edge. – Torbjørn T. Mar 09 '14 at 18:25

1 Answers1

3

You can always define styles.

There are lots of styles available, among them

  • every axis post : allows to override all options after \begin{axis} set in your .tikz file
  • every tikzpicture : allows to define default options for every tikz picture. Useful keys could be trim axis left, trim axis right, and baseline. Please refer to Section "Alignment Options" of the pgfplots manual to learn how they can be used to fix alignment issues in plots.

These plots will be applied to all input pictures without the need to edit them.

However, it might seem confusing to assign, say, \pgfplotsset{every axis post/.style={width=4cm}} in the preamble if all your .tikz files define a width on their own... are you sure that you do not want to edit the files? Perhaps matlab2tikz can add some standard options?


Note that a best-practice would be to write

\begin{axis}[super style]

whenever you start an axis, combined with some preamble statement of sorts \pgfplotsset{super style/.style={title=My Title}}. Clearly, this would need modifications to your .tikz files.

  • Thank you so much. trim axis was the perfect solution, and the alignment section in the manual cleared up a lot for me. – Steve Hatcher Mar 10 '14 at 04:51