Probleme Tikzexternalize, wenn Legende in Plot

Tabellen und Grafiken erstellen und anordnen


pjheinrich

Probleme Tikzexternalize, wenn Legende in Plot

Beitrag von pjheinrich »

Hallo liebe Forianer,

ich habe folgendes Problem: Grundsätzlich funktioniert Tikzexternalize gut, wenn ich meine Plots gemeinsam mit pgfplots erzeuge. Problematisch wird es komischerweise, sobald ich eine Legende erzeuge bzw. irgendwelche \ref's im Plot haben möchte.

Folgendes Minimalbeispiel kompilliert bei mir problemlos (0 Fehler, 0 Warnungen):
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{fix-cm}
\documentclass[
a4paper,
11pt,
BCOR8mm,
numbers=noenddot,
oneside,
parskip=half, 
openright, 
fleqn,
bibliography=totoc, 
table,
DIV=14
]{scrbook}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{ae}
\usepackage{aecompl}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage[ngerman]{babel}
\usepackage{bibgerm}
\usepackage{bigstrut}
\usepackage{blkarray}
\usepackage{blindtext}
\usepackage{bm}
\usepackage{booktabs}
\usepackage{courier}
\usepackage{chngcntr}
\usepackage{float}
\usepackage{graphicx}

\usepackage[
  %pdftex=true,
  hypertexnames=false,
  plainpages=false,
  pdfpagelabels,
  pagebackref=false, 
  colorlinks=false, 
  bookmarks=true, 
  bookmarksopen=true, 
  bookmarksnumbered=true, 
  pdftitle={Dissertation},
  pdfauthor={TU},
  pdfsubject={PhD},
  pdfcreator={Accomplished with LaTeX2e and pdfLaTeX with hyperref-package.},
  pdfproducer={},                      
  pdfkeywords={IBB},
  pdfstartview=Fit, 
  pdfpagemode={UseOutlines},
]{hyperref}

\usepackage{ifthen}
\usepackage[latin1]{inputenc} 
\usepackage{listings} 
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage{marvosym}
\usepackage{multirow} 
\usepackage[square]{natbib}
\usepackage{ngerman} 
\usepackage[intoc]{nomencl}
\usepackage{overpic} 
\usepackage{pdfpages}
\usepackage{pgfplots}
\usepackage{pifont} 

\usepackage{rotating}
\usepackage[automark]{scrpage2} 
\usepackage{scrhack}
\usepackage{siunitx}
\usepackage{stmaryrd}
\usepackage{subcaption}
\usepackage{tabularx}
\usepackage{tikz}
\usepackage{todonotes}
\usepackage{units} 
\usepackage{upgreek}
\usepackage{url}
\usepackage{ucs}
\usepackage{wrapfig}
\usepackage{wasysym}
\usepackage{xfrac}

\graphicspath{{./img/bin/}} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepgfplotslibrary{external}

%% Tikz
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{backgrounds}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.text}
\usetikzlibrary{external}
\usetikzlibrary{math}
\usetikzlibrary{matrix}
\usetikzlibrary{shapes}

\tikzexternalize % [shell escape=-enable-write18,optimize command away=\includepdf]
\tikzsetexternalprefix{img_exp/}

% Basisdefinition
\pgfplotsset{
  compat=1.10,
  table file path/.initial={{./data/}}, 
  height=6cm,
  width=15cm,
  grid=major,
  grid style={
    solid,
	  thin,
	  gray
  },
	x tick label style={
    font=\footnotesize,     
  },
	x label style={
    font=\footnotesize,     
  },    
	y tick label style={
    font=\footnotesize,     
  },
	y label style={
    font=\footnotesize,     
  },   
  /pgf/number format/.cd,
  use comma,
  set thousands separator={}  
}

% Pfadeinstellung
\makeatletter
\def\pgfplotstableread@openfile{%
    \def\pgfplotstable@loc@TMPa{\pgfutil@in@{ }}%
    \expandafter\pgfplotstable@loc@TMPa\expandafter{\pgfplotstableread@filename}%
    \ifpgfutil@in@
        \t@pgfplots@toka=\expandafter{\pgfplotstableread@filename}%
        \edef\pgfplotstableread@filename{\pgfplots@dquote\the\t@pgfplots@toka\pgfplots@dquote}%
    \fi
    \let\pgfplotstableread@old@crcr=\\%
    \def\\{\string\\}% just to make sure we don't try to open inline table data...
    \openin\r@pgfplots@reada=\csname pgfk@/pgfplots/table file path\endcsname\pgfplotstableread@filename.tex
    \ifeof\r@pgfplots@reada
        \openin\r@pgfplots@reada=\csname pgfk@/pgfplots/table file path\endcsname\pgfplotstableread@filename\relax
    \else
        \pgfplots@warning{%
            You requested to open table '\pgfplotstableread@filename', but there is also a '\pgfplotstableread@filename.tex'. 
            TeX will automatically append the suffix '.tex', so I will now open '\pgfplotstableread@filename.tex'.
            Please make sure you don't accidentally load TeX files - this may produce unrecoverable errors.}%
        \closein\r@pgfplots@reada
        \openin\r@pgfplots@reada=\pgfplotstableread@filename\relax
    \fi
    %
    \ifeof\r@pgfplots@reada
        \pgfplotsthrow{no such table file}{\pgfplots@loc@TMPa}{\pgfplotstableread@filename}{Could not read table file '\csname pgfk@/pgfplots/table file path\endcsname\pgfplotstableread@filename'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try `row sep=crcr' and terminate your lines with `\string\\' (refer to the pgfplotstable manual for details)}\pgfeov%
        \global\let\pgfplotstable@colnames@glob=\pgfplots@loc@TMPa
        \def\pgfplotstableread@ready{0}%
    \fi
    \pgfplots@logfileopen{\pgfplotstableread@filename}%
    \let\\=\pgfplotstableread@old@crcr
}
\makeatother


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
  \begin{figure}[htbp]
    \centering
    \begin{tikzpicture}
      \pgfplotsset{
        height=5.0cm,
        width=10.5cm
      }
      \begin{axis}[
        xmin=-2,
        xmax=2,
        ymin=-2,
        ymax=2,
        y tick label style={
          /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=2,
         /tikz/.cd
        },
       xlabel={Zeit $t$},
       ylabel={Spektralwert $K$},
      ] 
        \addplot {sin(deg(x))}; 
        \label{plot:spektrk1}
    
        % Legende
%        \matrix[
%          matrix of nodes,
%          anchor=south west,
%          inner sep=0.2em,
%          fill=white,  
%          %nodes={font=\Large},
%        ] at([yshift=2ex, xshift=2ex]current axis.south west)
%        {
%          \ref{plot:spektrk1}& \small{$k = 1$}\\
%        };          
        \end{axis}
      \end{tikzpicture} 
    \caption{Approximationen unterschiedlicher Ordnung}
    \label{fig:approximation}
  \end{figure}
\end{document}
(Da das der Ausschnitt aus einem größeren Dokument ist, habe ich alle \usepackages{} drinnengelassen, die ich auch dort verwende ... nicht dass der Fehler mit irgendeiner Packagekollission zu tun hat ...)

Sobald ich nun die Legende einfüge (also den im Beispiel auskommentierten Teil einkommentiere) gibt es folgenden Fehler:
===== tikzexternal: \end{document} reached. Working on rescheduled images to re
solve references... ========
===== 'mode=convert with system call': Invoking 'pdflatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "img_exp/testdoc-figure0" "\def\tikzext
ernalrealjob{testdoc}\input{testdoc}"' ========
runsystem(pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname
 "img_exp/testdoc-figure0" "\def\tikzexternalrealjob{testdoc}\input{testdoc}").
..executed.


! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "img_exp/testdoc-figure0" "\def\tikzextern
alrealjob{testdoc}\input{testdoc}"' did NOT result in a usable output file 'img
_exp/testdoc-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify th
at you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape
'. Sometimes it is also named 'write 18' or something like that. Or maybe the c
ommand simply failed? Error messages can be found in 'img_exp/testdoc-figure0.l
og'. If you continue now, I'll try to typeset the picture.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.214 \end{document}
                    
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
... im *.log der entsprechenden figure0 steht dann:
[...]
<argument> \pgf@matrix@last@nextcell@options 
                                             
l.209         \end{axis}
                         
Here is how much of TeX's memory you used:
 50429 strings out of 493334
 1153591 string characters out of 3139241
 1379165 words of memory out of 3000000
 53068 multiletter control sequences out of 15000+200000
 55655 words of font info for 86 fonts, out of 3000000 for 9000
 1141 hyphenation exceptions out of 8191
 74i,21n,109p,10478b,3006s stack positions out of 5000i,500n,10000p,200000b,50000s

!  ==> Fatal error occurred, no output PDF file produced!
- Ich hab' leider absolut keinen Plan, was hier nicht passt bzw. woran der Fehler liegt. Vielleicht kann mir jemand von euch weiterhelfen?

Ich verwende TechnicCenter und -shel-escape ist im entsprechenden Ausgabeprofil aktiviert.

Vielen lieben Dank im Voraus,
pjheinrich

Bartman
Forum-Meister
Forum-Meister
Beiträge: 2456
Registriert: Do 16. Jul 2009, 21:41
Wohnort: Hessische Provinz

Beitrag von Bartman »

Entferne die Matrix an der gegenwärtigen Stelle und füge sie zwischen \end{axis} und \end{tikzpicture} ein.

Der Quelltext für die Einstellung der Schriftgröße an den Achsen kann auch kürzer ausfallen:
  every axis/.append style={
    font=\footnotesize
  },
%    x tick label style={
%     font=\footnotesize,    
%   },
%    x label style={
%     font=\footnotesize,    
%   },    
%    y tick label style={
%     font=\footnotesize,    
%   },
%    y label style={
%     font=\footnotesize,    
%   },  

pjheinrich

Beitrag von pjheinrich »

Entferne die Matrix an der gegenwärtigen Stelle und füge sie zwischen \end{axis} und \end{tikzpicture} ein.
Vielen lieben Dank, das hat geholfen. Danke auch f die Info bzgl. des kürzeren Quelltexts.

Leider gibt's ein Problem noch. Durch die Änderung läuft das Minimalbeispiel durch, ganz ohne Probleme; in meinem großen Dokument allerdings können die \ref's nicht aufgelöst bzw. gefunden werden, und ich erhalte immer folgende Warnung:
"LaTeX Warning: External picture 'img_exp/diss_pjh-figure1' contains undefined references on input line 62."
Das kann ich nicht nachvollziehen, zumal ich das \addplots{} mit \label{xyz} versehen habe; in der Legende wird dann mit \ref{xyz} darauf "zugegriffen". Aber das klappt anscheinend nicht.

Ich weiß nicht, wo bzw. wie ich diesen Fehler am besten aufspüren könnte bzw. was die Ursache ist oder sein könnte ...

Hat jemand eine Idee? Oder zwei? :)

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Ohne mir das jetzt selbst noch mal genau angesehen zu haben, aber vielleicht hilft Dir Labels an pgfplots weiter.

Antworten