
我正在嘗試繪製最大化問題的可行集。其中一個限制是不完整的,因為它應該一直延伸到 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)
右側評估該函數。 - 點被丟棄 - 看編譯日誌。一種可能性是大幅增加樣本數量,以便倒數第二個點給出可接受的結果。另一種方法是用 a 單獨定義點,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}