以下代码使图例显示在图表上(并且图表的尺寸太小):
\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,
backgrounds, bending,
calc, chains,
%decorations.pathmorphing,
fit,
%petri,
positioning,
trees,
quotes,
shapes.misc}
\definecolor{darkblue}{RGB}{31,22,70}
\definecolor{darkblue2}{RGB}{21,126,251}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.geometric,intersections,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{textcomp}
\usepackage{wrapfig}
\usepackage{siunitx}
\begin{document}
\begin{wrapfigure}{r}{0.5\textwidth}
\begin{tikzpicture}
\begin{axis}[
title={x},
xlabel={xx},
ylabel={Temps [$Secondes$]},
xmin=0, xmax=1000,
ymin=0, ymax=25,
xtick={20,100,200,500,1000},
ytick={0,5,10,15,20,25},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=red,
mark=halfcircle*,
]
coordinates {(0,0) (5,5)(50,7)(100,9)(200,9)(500,9.5)(750,9)(1000,9.5)};
\legend{xx}
\addplot[
color=cyan,
mark=halfcircle*,
]
coordinates {(0,0) (5,5)(50,12)(100,25)(200,20)(500,15)(750,20)(1000,27)};
\addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{xx}
\end{axis}
\end{tikzpicture}
\caption{A gull}
\end{wrapfigure}
\end{document}
我该如何解决这个问题?谢谢
答案1
您可以通过轴选项width=<width>
和缩放图形height=<height>
。另一种可能性是\resizebox {\textwidth}{\height}
在 内使用wrapfigure
。请记住 也会\resizebox
缩放 内的字体大小tikzpicture
。不过,如果您使用这些解决方案,wrapfigure
您还必须注意其宽度。
您可以使用以下方式调整图例的位置legend style={at={(<x>,<y>)},anchor=<name>}
输出wrapfigure
和轴选项:
代码:
\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,
backgrounds, bending,
calc, chains,
%decorations.pathmorphing,
fit,
%petri,
positioning,
trees,
quotes,
shapes.misc}
\definecolor{darkblue}{RGB}{31,22,70}
\definecolor{darkblue2}{RGB}{21,126,251}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.geometric,intersections,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{textcomp}
\usepackage{wrapfig}
\usepackage{siunitx}
\begin{document}
\begin{wrapfigure}{r}{1.0\textwidth}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
height=\axisdefaultheight,
title={x},
xlabel={xx},
ylabel={Temps [$Secondes$]},
xmin=0, xmax=1000,
ymin=0, ymax=25,
xtick={20,100,200,500,1000},
ytick={0,5,10,15,20,25},
% legend pos=north west,
legend style={at={(1.05,1.0)},anchor=north}, % legend pos=outer north east,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=red,
mark=halfcircle*,
]
coordinates {(0,0) (5,5)(50,7)(100,9)(200,9)(500,9.5)(750,9)(1000,9.5)};
\legend{xx}
\addplot[
color=cyan,
mark=halfcircle*,
]
coordinates {(0,0) (5,5)(50,12)(100,25)(200,20)(500,15)(750,20)(1000,27)};
\addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{xx}
\end{axis}
\end{tikzpicture}
\caption{A gull}
\end{wrapfigure}
\end{document}
输出wrapfigure
和resizebox
:
代码:
\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,
backgrounds, bending,
calc, chains,
%decorations.pathmorphing,
fit,
%petri,
positioning,
trees,
quotes,
shapes.misc}
\definecolor{darkblue}{RGB}{31,22,70}
\definecolor{darkblue2}{RGB}{21,126,251}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.geometric,intersections,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{textcomp}
\usepackage{wrapfig}
\usepackage{siunitx}
\begin{document}
\begin{wrapfigure}{r}{1.0\textwidth}
\resizebox {\textwidth}{!} {
\begin{tikzpicture}
\begin{axis}[
% width=\textwidth,
% height=\axisdefaultheight,
title={x},
xlabel={xx},
ylabel={Temps [$Secondes$]},
xmin=0, xmax=1000,
ymin=0, ymax=25,
xtick={20,100,200,500,1000},
ytick={0,5,10,15,20,25},
% legend pos=north west,
legend style={at={(1.15,1.0)},anchor=north}, % legend pos=outer north east,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=red,
mark=halfcircle*,
]
coordinates {(0,0) (5,5)(50,7)(100,9)(200,9)(500,9.5)(750,9)(1000,9.5)};
\legend{xx}
\addplot[
color=cyan,
mark=halfcircle*,
]
coordinates {(0,0) (5,5)(50,12)(100,25)(200,20)(500,15)(750,20)(1000,27)};
\addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{xx}
\end{axis}
\end{tikzpicture}
}
\caption{A gull}
\end{wrapfigure}
\end{document}