我正在尝试绘制最大化问题的可行集。其中一个限制是不完整的,因为它应该一直延伸到 x 轴。
另外,我猜测center
环境会导致整个图形+标题相对于页面居中,但我希望图形也相对于标题居中。
MWE 是
\documentclass[a4paper]{article}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\begin{document}
\begin{center}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
xmin=0,xmax=1.2,
ymin=0,ymax=1.3]
\addplot[
domain = 0:sqrt(33/56),
samples =200,
smooth,
blue,
thick
] {sqrt((33/8-7*x^2)/3)};
\end{axis}
\end{tikzpicture}
\caption{This is text just to show that the figure is not centered with respect to the caption.}
\end{figure}
\end{center}
\end{document}
答案1
扩展@RaffaeleSantoro 的答案:
使用samples = 800
帮助。
另外,不要放在环境figure
里面center
,而是像这样\centering
使用:figure
\documentclass[a4paper]{article}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
xmin=0,xmax=1.2,
ymin=0,ymax=1.3]
\addplot[
domain = 0:sqrt(33/56),
samples =800,
smooth,
blue,
thick
] {sqrt((33/8-7*x^2)/3)};
\end{axis}
\end{tikzpicture}
\caption{This is text just to show that the figure is not centered with respect to the caption.}
\end{figure}
\end{document}
答案2
这并不是因为最后一个点没有“到达”。函数没有在右侧定义,sqrt(33/56)
并且计算机的有限精度也不可能在sqrt(33/56)
右侧评估函数。-该点被丢弃 - 查看编译日志。一种可能性是大幅增加样本数量,以便倒数第二个点给出可接受的结果。另一种方法是单独定义该点,如下所示y filter
:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
xmin=0,xmax=1.2,
ymin=0,ymax=1.3]
\addplot[
domain=0:sqrt(33/56),
samples=200,
smooth,
blue, thick,
y filter/.expression={x==sqrt(33/56)?0:y},
] {sqrt((33/8-7*x^2)/3)};
\end{axis}
\end{tikzpicture}
\end{document}