1

I'm using matlab2tikz in order to generate pgfplots .tex code to create a figure with pdflatex. The matlab function I'm using to create the figure creates each of it's tickmark labels explicitly, so that they may be scaled and rotated using the following matlab code:

text(x(k),y(k),labs{k},'horizontalalignment',horizk,...
'verticalalignment',vertk, ...
'rotation',rotang(k), ...
'fontsize',gfontsize*scl(k), ...
'color',gcolor, ...
'tag','m_grid_xticklabel', ...
'fontname',gfontname);

When I investigate the converted .tex code, I see that the following

\node[below, inner sep=0mm, rotate=359.994889043193, text=black]
at (axis cs:-8.79858922562881e-07,  -4.84813663392814e-06,0) {$\text{  81}^\text{o}\text{W }$};

represents a single tick mark label. The text string for which this line codes does not, however, appear in the resulting .pdf, presumably because the particular coordinates lie outside of the ranges of the axes. To test this, I substituted in-range coordinates, compiled, and saw that the label or text then became visible.

Interestingly, if I create the figure in matlab using the view command, e.g.

view(45,45)

I am able to see the text strings representing the axis labels, but the alignment is off. In particular, the strings appear to have a y-value which places them far higher up on the figure than I expect. I think that the x-alignment is ok.

The solutions as I see them may reside on either the matlab side or on the pgfplots/tikz side. Ideally, a solution would consist of a short bit of code to be included in the preamble or when setting up the axis labels. This code would allow text created with the construct:

\node[<options>] at (axis cs:x,y,z) {<text>};

to be displayed regardless of whether the coordinates x, y, z were in range. If suggestions don't necessarily come forth easily, I can create a mwe.

  • 3
    This is why I don't recommend matlab2tikz: $\text{ 81}^\text{o}\text{W }$ What on earth is that supposed to be? Superscript o used instead of the degree symbol? Anyway, a quick solution might be to add clip=false to the axis environment options. Beyond that, we'll need an MWE to have any hope. – Paul Gessler Feb 21 '15 at 14:56
  • The clip option works. Note that the following matlab code can be placed before the m2t call: EXTRAAXISOPTIONS = {'clip=false'}; – John Chris Feb 21 '15 at 16:07
5

Adding clip=false to the axis environment options will override the default pgfplots behavior of clipping anything appearing outside the bounding box of the axis.

Depending on the other generated code, this may have other side effects, but in most cases it will be OK.

This key setting can be added to the generated code by using matlab2tikz's EXTRAAXISOPTIONS facility. Before the call to matlab2tex, add

EXTRAAXISOPTIONS = {'clip=false'};

to add this option in the generated code.

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.