2

Since the paraview legends look horrible when they appear inside a latex document, I want to replace them using Python's matplotlib and Nico's matplotlib2tikz package.

So I have compiled a python script matplotlib4colorbars, that produces a tikz file, which can then be included in a tex document. The tex part in a single file reads (you will have to download the included image img1.png to produce the output)

\documentclass[a4paper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

%opening
\begin{document}

\begin{figure}
    \newlength\figureheight
    \newlength\figurewidth
    \setlength\figureheight{8.5cm}
    \setlength\figurewidth{2cm}
%   \input{colorbar.tikz}
\begin{tikzpicture}

\begin{axis}[
title={$\mathbf{v_x}$},
xmin=0, xmax=0.07635,
ymin=-0.247, ymax=1.28,
axis on top,
scaled x ticks=false,
xtick={,,},
xticklabels={,,},
width=\figurewidth,
height=\figureheight
]
\addplot graphics [includegraphics cmd=\pgfimage,xmin=0, xmax=0.07635, ymin=-0.247, ymax=1.28] {img1.png};
\path [draw=black, fill opacity=0] (axis cs:13,1.28)--(axis cs:13,1.28);

\path [draw=black, fill opacity=0] (axis cs:0.07635,13)--(axis cs:0.07635,13);

\path [draw=black, fill opacity=0] (axis cs:13,-0.247)--(axis cs:13,-0.247);

\path [draw=black, fill opacity=0] (axis cs:0,13)--(axis cs:0,13);

\end{axis}

\end{tikzpicture}
\end{figure}

\end{document}

and it produces , which I find more attractive than the paraview legend enter image description here

However, I could not reproduce the prominent yticklabels. So the question is, how to make that the pgfplot has the margin points as labels? And, how to make these margin labels a bit larger than the others?

1 Answer 1

3

You can use the feature of adding extra ticks. Include the key extra y ticks={<ymin>, <ymax>} where you can manually write the values <ymin> and <ymax> to the axis environment. You can also use extra y ticks={\pgfkeysvalueof{/pgfplots/ymin}, \pgfkeysvalueof{/pgfplots/ymax}} since you have already explicitly specified the limits ymin and ymax in the axis environment keys.

To make the extra ticklabels larger than the other ticklabels, specify a style with every extra y tick/.style={font=\large}.

So the axis environment should be something like

\begin{axis}[
title={$\mathbf{v_x}$},
xmin=0, xmax=0.07635,
ymin=-0.247, ymax=1.28,
axis on top,
scaled x ticks=false,
xtick={,,},
xticklabels={,,},
extra y ticks={
    \pgfkeysvalueof{/pgfplots/ymin},
    \pgfkeysvalueof{/pgfplots/ymax}
},
% alternatively
% extra y ticks={-0.247, 1.28},
every extra y tick/.style={
    font=\large,
    tick style=transparent, % avoid tick marks overlapping axis lines
    /pgf/number format/.cd,
    fixed,
    precision=3
},
width=\figurewidth,
height=\figureheight
]

Which gives the output

Extra ticks.

This causes the ticklabels to be very tight, so a possibility is to include yticklabel pos=right in the style every extra y tick/.style.

\begin{axis}[
title={$\mathbf{v_x}$},
xmin=0, xmax=0.07635,
ymin=-0.247, ymax=1.28,
axis on top,
scaled x ticks=false,
xtick={,,},
xticklabels={,,},
extra y ticks={
    \pgfkeysvalueof{/pgfplots/ymin},
    \pgfkeysvalueof{/pgfplots/ymax}
},
% alternatively
% extra y ticks={-0.247, 1.28},
every extra y tick/.style={
    font=\large,
    tick style=transparent, % avoid tick marks overlapping axis lines
    yticklabel pos=right,
    /pgf/number format/.cd,
    fixed,
    precision=3
},
width=\figurewidth,
height=\figureheight
]

This gives the output

Extra ticks on the right side.

If you want the bigger numbers on the left side, simply include

yticklabel pos=right,
every extra y tick/.style={
    font=\large,
    tick style=transparent, % avoid tick marks overlapping axis lines
    yticklabel pos=left,
    /pgf/number format/.cd,
    fixed,
    precision=3
}

Extra ticks on the left side, normal ticks on the right side.

0

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.