如何在同一文档中正确使用由 matlab2tikz 和常见的 tikzpicture-polaraxis 创建的图?
该示例属于结构包,matlab2tikz-pic1、matlab2tikz-pic2 和 polaraxis-pic。
matlab2tikz 图片只是复制粘贴。它们与 \begin{document} 之后使用的以下代码行配合良好(根据其来源)
\pgfplotsset{compat=1.3,
every axis legend/.style={
y tick label style={/pgf/number format/1000 sep=},
x tick label style={/pgf/number format/1000 sep=}}}
\newlength\figureheight
\newlength\figurewidth
这些线严重影响了 polaraxis-pic 中的图例(框架和对齐)。
将这些行放在相应的图形环境中(在 \begin{figure} 之后)第一次才有效。第二次调用会创建一个“已定义”错误消息。
在 \begin{tikzpicture} 中放入更深的一层会导致 texmaker 挂断。
有什么建议么?
\documentclass[12pt,a4paper]{report}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[ngerman]{babel} % Sprache mit Umlauten
\usepackage[{top=3cm,bottom=3cm,left=3cm,right=2cm}]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc} % Kodierung
\usepackage{mathcomp}
\usepackage{pgfplots} % für matlab2tikz
\usepgfplotslibrary{polar} % für Polarplots
\usetikzlibrary{shapes.geometric} % für Polarplots
\setlength{\parindent}{0pt}
\newcommand{\xfrac}[2]{%
\mbox{\raisebox{0.6ex}{\ensuremath{\displaystyle #1}}%
{\Large /}%
\raisebox{-0.6ex}{\ensuremath{\displaystyle #2}}}}
\begin{document}
\begin{figure}[h]
\pgfplotsset{compat=1.3,
every axis legend/.style={
y tick label style={/pgf/number format/1000 sep=},
x tick label style={/pgf/number format/1000 sep=}}}
\newlength\figureheight
\newlength\figurewidth
\begin{center}
\footnotesize
\setlength\figureheight{4cm}
\setlength\figurewidth{8cm}
% This file was created by matlab2tikz v0.4.2.
\begin{tikzpicture}
\begin{axis}[
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=0,
xmax=5,
xlabel={Tiefe [$\mu$m]},
ymin=0,
ymax=105,
ylabel={Temperaturanstieg [K]}
]
\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0 98.3383266017213\\
0.6 75.7037719551423\\
1.4 44.0308586761605\\
1.8 31.8836282059977\\
2.6 15.3339893333299\\
3.9 3.79795619734343\\
5 0.987919017813002\\
};
\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.5 80.10874197629\\
1 90.10874197629\\
};
\node[above, right, inner sep=0mm, text=black]
at (axis cs:1,90.10874197629,0) {\scriptsize 30 ns, 0 mm};
\end{axis}
\end{tikzpicture}%
\hspace{2cm}
\end{center}
\caption{Text}
\end{figure}
%%\begin{figure}[h]
%\pgfplotsset{compat=1.3,
% every axis legend/.style={
% y tick label style={/pgf/number format/1000 sep=},
% x tick label style={/pgf/number format/1000 sep=}}}
% \newlength\figureheight
% \newlength\figurewidth
%\begin{center}
%\footnotesize
%\setlength\figureheight{4cm}
%\setlength\figurewidth{8cm}
%% This file was created by matlab2tikz v0.4.2.
%\begin{tikzpicture}
%\begin{axis}[
%width=\figurewidth,
%height=\figureheight,
%scale only axis,
%xmin=0,
%xmax=5,
%xlabel={Tiefe [$\mu$m]},
%ymin=0,
%ymax=105,
%ylabel={Temperaturanstieg [K]}
%]
%\addplot [
%color=black,
%solid,
%forget plot
%]
%table[row sep=crcr]{
%0 98.3383266017213\\
%0.6 75.7037719551423\\
%1.4 44.0308586761605\\
%1.8 31.8836282059977\\
%2.6 15.3339893333299\\
%3.9 3.79795619734343\\
%5 0.987919017813002\\
%};
%\addplot [
%color=black,
%solid,
%forget plot
%]
%table[row sep=crcr]{
%0.5 80.10874197629\\
%1 90.10874197629\\
%};
%\node[above, right, inner sep=0mm, text=black]
%at (axis cs:1,90.10874197629,0) {\scriptsize 30 ns, 0 mm};
%\end{axis}
%\end{tikzpicture}%
%\hspace{2cm}
%\end{center}
%\caption{Text1}
%\end{figure}
\begin{figure}[h]
\begin{center}
\footnotesize
\begin{tikzpicture}
\definecolor{lgray}{rgb}{0.7,0.7,0.7}
\definecolor{dgray}{rgb}{0.3,0.3,0.3}
\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
xticklabel style={
inner xsep=1pt,
ellipse,
anchor=\tick-(180-\pgftransform@angle)
},
yticklabel style={
anchor=90 + \pgftransform@angle
}
}
\makeatother
\begin{polaraxis}[
rotate=-90,
xmin=00,
xmax=90,
%xtick={0,30,60,90}
xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
xtick={0,15,...,90},
legend style={xshift=3.5cm,yshift=-.2cm}
%legend style={anchor=north west, at={(axis cs:45,4)}}
]
\addplot[red,no markers,smooth] table{
0 1
30 2
60 3
90 2
};
\addlegendentry{Text1}
\addplot[no markers,smooth] table{
0 2
30 3
60 1
90 1
};
\addlegendentry{Text2}
\end{polaraxis}
\end{tikzpicture}
\hspace{2cm}
\end{center}
\caption{Text}
\end{figure}
\end{document}
答案1
通过添加 \pgfplotsset-lines 解决仅有的进入第一个图形环境。
可以工作,但似乎不是好的编程。仍然欢迎提出建议!