我找不到有关此特定问题的任何讨论。我是 LaTeX 新手。
我有抛物线 x = -(y - 3) + 3。它应该是水平的并且向左开放。
当我尝试编译它时,pgfplots 给出了错误“抱歉,您不能在该上下文中使用“y””。
第一个 \addplot 中的坐标是抛物线应该是。
\documentclass[pstricks, 12pt, letterpaper]{article}
\usepackage{scrextend}
\usepackage{geometry}
\usepackage{pgfplots}
\usepackage{pstricks}
\pgfplotsset{compat=1.18}
\begin{document}
\newgeometry{top=1.5cm,left=1.5cm,right=1.5cm,bottom=1.5cm}
\begin{flushright}
\end{flushright}
\begin{addmargin}[0em]{15em}
\begin{center}
\begin{tikzpicture}
\begin{axis}[width=10cm, height=10cm, xmin=-12, xmax=12, ymin=-12, ymax=12, axis lines = middle, xlabel=x, ylabel=y,
xtick={-12, -10,...,12},
minor xtick={-11, -9,...,11},
ytick={-12, -10,...,12},
minor ytick={-11, -9,...,11},
tick style={very thick},
grid=both, ]
\addplot [blue, only marks] coordinates {
(3, 3)
(0, {3 + sqrt(3)})
(0, {3 - sqrt(3)})
(-6, 6)
(0, {3 - sqrt(3)})
(-6, 0)};
\addplot [blue, no marks, <->, line width=1]{-(y - 3)^2 + 3};
\end{axis}
\end{tikzpicture}
\end{center}
\end{addmargin}
\end{document}
所以我做了一些研究,找到了有关 rotate 选项的信息。我将 x 改为 ay,并添加 rotate=-90。
然而,它似乎围绕某个遥远的点旋转抛物线,导致其消失。
我通过在以下代码中将 rotate=-90 改为 rotate=-5 来解决这个问题。抛物线部分围绕负 y 轴上的某个点旋转。
它以正确的方向旋转,但围绕的是错误的点。我能以某种方式让它围绕顶点旋转吗?谢谢您的帮助!
\documentclass[pstricks, 12pt, letterpaper]{article}
\usepackage{scrextend}
\usepackage{geometry}
\usepackage{pgfplots}
\usepackage{pstricks}
\pgfplotsset{compat=1.18}
\begin{document}
\newgeometry{top=1.5cm,left=1.5cm,right=1.5cm,bottom=1.5cm}
\begin{flushright}
\end{flushright}
\begin{addmargin}[0em]{15em}
\begin{center}
\begin{tikzpicture}
\begin{axis}[width=10cm, height=10cm, xmin=-12, xmax=12, ymin=-12, ymax=12, axis lines = middle, xlabel=x, ylabel=y,
xtick={-12, -10,...,12},
minor xtick={-11, -9,...,11},
ytick={-12, -10,...,12},
minor ytick={-11, -9,...,11},
tick style={very thick},
grid=both, ]
\addplot [blue, only marks] coordinates {
(3, 3)
(0, {3 + sqrt(3)})
(0, {3 - sqrt(3)})
(-6, 6)
(0, {3 - sqrt(3)})
(-6, 0)};
\addplot [blue, no marks, <->, line width=1, rotate=-5]{-(x - 3)^2 + 3};
\end{axis}
\end{tikzpicture}
\end{center}
\end{addmargin}
\end{document}
答案1
像这样:
使用tikz
代码(最少,但带有轴和网格):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[gray!20] (-13,-1) grid (9,20);
\draw[-latex] (-13,0)--(9,0) node[right] () {x};
\draw[-latex] (0,-1)--(0,20) node[above] () {y};
\draw[line width=1pt,dashed] plot[domain=-1:7,smooth] (\x,{\x*\x-6*\x+12});
\draw[rotate around={90:(3,3)},red,line width=2pt] plot[domain=-1:7,smooth] (\x,{\x*\x-6*\x+12});
\end{tikzpicture}
\end{document}
答案2
欢迎来到 TeX.SE!
为了获得期望的结果,您应该尝试绘制反演函数y=sqrt(x-3)+3
::
%\documentclass[pstricks, 12pt, letterpaper]{article}
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%width=10cm, height=10cm,
axis lines = middle,
grid=both,
minor tick num = 1,
minor grid style = {densely dashed, very thin},
axis on top,
%
xlabel=$x$, ylabel=$y$,
xmin=-10, xmax=10,
ymin=-10, ymax=10,
enlargelimits=0.05,
xtick={-10,-8,...,10},
ytick={-10,-8,...,10},
ticklabel style={fill=white, font=\scriptsize,
inner sep=1pt, outer sep=1pt},
%
samples=501, no marks,
every axis plot post/.append style={blue, line width=1}
]
\addplot [blue, only marks] coordinates {
(3, 3)
(0, {3 + sqrt(3)})
(0, {3 - sqrt(3)})
(-6, 6)
(0, {3 - sqrt(3)})
(-6, 0)};
\addplot +[->, domain =4:-9] {-sqrt(-x+3)+3};
\addplot +[<-, domain =-9:4] {+sqrt(-x+3)+3};
\end{axis}
\end{tikzpicture}
\end{document}
附录:
@Raffaele Santoro 的回答 (+1) 中展示了更简单的解决方案tikz
。这里显示,他的好主意在使用时也能很好地工作pgfplots
:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=10cm, height=10cm,
axis lines = middle,
grid=both,
minor tick num = 1,
minor grid style = {densely dashed, very thin},
axis on top,
%
xlabel=$x$, ylabel=$y$,
xmin=-10, xmax=10, xtick distance = 2,
ymin=-10, ymax=10, ytick distance = 2,
enlargelimits=0.05,
ticklabel style={fill=white, font=\scriptsize,
inner sep=1pt, outer sep=1pt},
%
domain =-0.5:6.5, samples=101, no marks,
every axis plot post/.append style={blue, thick, <->}
]
\addplot [blue, only marks] coordinates {
(3, 3)
(0, {3 + sqrt(3)}) (0, {3 - sqrt(3)})
(-6, 3 + 3) (-6, 3 - 3)};
\addplot [rotate around={90:(3,3)}] {(x - 3)^2 + 3};
\addplot [dashed] {(x - 3)^2 + 3};
\end{axis}
\end{tikzpicture}
\end{document}