这是一个后续问题使用“轮廓 gnuplot”和“轴线 = 中间”时不显示刻度标签。不同之处在于我在代码中添加了网格线。但是它没有绘制它。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.16}
\begin{document}
\begin{tikzpicture} \begin{axis}[
axis lines = middle,
title={$x^2-x\,y$},
enlarge x limits,
view={0}{90},
xlabel=$x$, ylabel=$y$,
small,
% grid
grid = both,
grid style = {line width = .1pt, draw = gray!10},
major grid style = {line width = .2pt, draw = gray!50},
ticks = both,
minor tick num = 4,
]
\addplot3[domain=-3:3,
domain y=-3:3,
contour gnuplot={levels={-1,1},labels=false},
thick,samples=50,samples y=50,
] {x^2-x*y};
\end{axis}
\end{tikzpicture}
\end{document}
我尝试移动线条的顺序,但问题没有解决。我该如何绘制网格线?
答案1
一个简单的渐近线解决方案怎么样?PS:我相信pgfplots
如果你看看其 571 页的文档足够小心。
\documentclass[border=5mm]{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}
import math; // for grids
import contour;
unitsize(1cm);
// grid and subgrid
add(shift(-3,-3)*scale(.2)*grid(30,30,.1gray+.9white));
add(shift(-3,-3)*grid(6,6,.5gray+.5white));
// axes, dashed line and labels
draw(Label("$x$",EndPoint,align=SW,Fill(white)),(-3,0)--(3,0));
draw(Label("$y$",EndPoint,align=SE,Fill(white)),(0,-3)--(0,3));
draw((1,0)--(1,2)--(0,2)^^(-1,0)--(-1,-2)--(0,-2),dashed);
label("$1$",(1,0),SE); label("$-1$",(-1,0),NW);
label("$2$",(0,2),W); label("$-2$",(0,-2),NW);
// plotting graph of implicit function
real f(real x, real y){return x^2-x*y;}
pair A=(-3,-3), B=(3,3);
real[] c1={1}, c2={-1}, c={0};
draw(contour(f,A,B,c,300),purple); // 2 asymptote straight lines
draw(contour(f,A,B,c1),blue);
draw(contour(f,A,B,c2),red);
label("The graph of $x^2-xy=C$",truepoint(S)+(0,-.5));
\end{asy}
\end{document}
更新对于“自动标记”,我使用和命令中的 来添加Step=1
网格和子网格。必须加载模块。编译时间似乎有点慢。step=.2
LeftTicks
RightTicks
xaxis
yaxis
graph
// http://asymptote.ualberta.ca/
unitsize(1cm);
import graph;
import contour;
real f(real x, real y){return x^2-x*y;}
pair A=(-3,-3), B=(3,3);
real[] c1={1}, c2={-1};
draw(A--B^^(0,A.y)--(0,B.y),purple); // 2 asymptote straight lines
draw(contour(f,A,B,c1),cyan+linewidth(1pt));
draw(contour(f,A,B,c2),magenta+linewidth(1pt));
pen thin=gray+linewidth(.2pt);
pen verythin=lightgray+linewidth(.2pt);
xaxis("$x$",BottomTop,LeftTicks(begin=false,end=false,Step=1,step=.2,extend=true, ptick=verythin,pTick=thin));
yaxis("$y$",LeftRight,RightTicks(begin=false,end=false,Step=1,step=.2,extend=true,ptick=verythin,pTick=thin));
label("The graph of $x^2-xy=C$",truepoint(N)+(0,.5));
答案2
grid
您正在创建一个 3D 图并旋转它,因此它看起来像一个 2D 图。PGFPlots中没有3D 图。您可以像这样手动添加它:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={$x^2-x\,y$},
axis lines=middle, view={0}{90},
xmin=-3.6, xmax=3.6,
ymin=-2.8, ymax=2.8,
xlabel=$x$, ylabel=$y$,
minor tick num=4,
small,
]
\addplot3[mesh, gray!10, domain=-3.6:3.6, samples=37, domain y=-2.8:2.8, samples y=29, forget plot] {0};
\addplot3[mesh, gray!50, domain=-4:4, samples=9, domain y=-3:3, samples y=7, forget plot] {0};
\addplot3[
domain=-3.2:3.2, samples=50,
domain y=-3:3, samples y=50,
contour gnuplot={levels={-1,1},labels=false},
thick,
] {x^2-x*y};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:实际上有一种 3D 网格。该选项3d box=complete
在 3D 框的侧面绘制完整的网格。 - 它与 不兼容axis lines=middle
。
3d box=complete
可以使用和 两个绘制相同的图axis
,如下所示:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
3d box=complete,
title={$x^2-x\,y$},
view={0}{90},
xmin=-3.6, xmax=3.6,
ymin=-2.8, ymax=2.8,
xlabel=$x$, ylabel=$y$,
grid=both,
minor tick num=4,
grid style = {line width = .1pt, draw = gray!10},
major grid style = {line width = .2pt, draw = gray!50},
axis line style={draw=none},
tick style={draw=none},
]
\end{axis}
\begin{axis}[
axis lines=middle,
view={0}{90},
xmin=-3.6, xmax=3.6,
ymin=-2.8, ymax=2.8,
]
\addplot3[
domain=-3.2:3.2, samples=50,
domain y=-3:3, samples y=50,
contour gnuplot={levels={-1,1},labels=false},
minor tick num=4,
thick,
] {x^2-x*y};
\end{axis}
\end{tikzpicture}
\end{document}