5

I have this tex file coming from matlab.

\begin{tikzpicture}
\begin{axis}[%
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=1,
xmax=5,
ymin=2,
ymax=10
]
\addplot [color=red,line width=4.0pt,only marks,mark=*,mark options={solid},forget plot]
  table[row sep=crcr]{
1   2   \\
2   4   \\
3   6   \\
4   8   \\
5   10  \\
};
\end{axis}
\end{tikzpicture}%

I want to add xlabel and ylabel inside it like

xmin=1,
xmax=5,
ymin=2,
ymax=10,
xlabel=X,
ylabel=Y,

if I run another latex file like mentioned here.

\documentclass{minimal}
\newwrite\tempfile
\begin{document}
\immediate\openout\tempfile=lists.tex
\immediate\write\tempfile{xlabel=X,}
\immediate\write\tempfile{ylabel=Y,}
\immediate\closeout\tempfile
\input{lists}
\end{document}

Can I write these to specific lines?

4
  • 3
    There may be a TeX-specific solution but I would use sed, the stream editor, for it. Mar 7 '14 at 7:50
  • Open the file, edit stuff, close the file. I really don't see where the problem is.
    – Johannes_B
    Aug 12 '15 at 11:11
  • Why don't you add the axis labels in Matlab in the first place? Aug 12 '15 at 11:21
  • If it is generic options you want to add to the axis environment, use the extraAxisOptions argument to matlab2tikz, e.g. matlab2tikz('file.tex','extraAxisOptions','xlabel=this,ylabel=that'). Aug 12 '15 at 11:24
2

The keys xlabel and ylabel can also be set outside of the tikzpicture from matlab via \pgfplotsset, e.g.:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\newdimen\figurewidth
\newdimen\figureheight

\begin{document}
\begingroup
  \pgfplotsset{xlabel=$X$, ylabel=$Y$}
  \setlength{\figurewidth}{5cm}
  \setlength{\figureheight}{5cm}
  % Matlab export
  \begin{tikzpicture}
  \begin{axis}[%
  width=\figurewidth,
  height=\figureheight,
  scale only axis,
  xmin=1,
  xmax=5,
  ymin=2,
  ymax=10
  ]
  \addplot [color=red,line width=4.0pt,only marks,mark=*,mark
  options={solid},forget plot]
    table[row sep=crcr]{
  1   2   \\
  2   4   \\
  3   6   \\
  4   8   \\
  5   10  \\
  };
  \end{axis}
  \end{tikzpicture}%
\endgroup
\end{document}

Result

1

A solution using only emacs replace-regexp function:

M-x replace-regexp RET \(ymax=[0-9]+\) RET \1, C-q C-j xlabel=X, C-q C-j ylabel=Y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.