KTUG 한국 텍 사용자 그룹

Menu

KTUG :: Q&A 마당 › pgfplots로 그린 좌표에서 격자를 표시하는 방법을 여쭙습니다.

고양이 | 2023.02.04 23:56:22 | 메뉴 건너뛰기 쓰기

아래와 같은 코드로 컴파일하면 tick에 적힌 숫자에서만 격자( grid)가 나오는데요. tick에 적힌 숫자를 그대로 유지하면서 (y축에 2,-10이 나오지 않아야 함, x축에 -6,6이 나오지 않아야 함. 원점은 영문자 O만 나오게 해야함.) 일단위로 격자가 나오게 하는 방법을 부탁드립니다. 인터넷에 검색해도 잘 안나오네요.

\documentclass[12pt]{standalone}
\usepackage{kotex}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz,pgfplots}
\usetikzlibrary{3d,calc,math,angles,positioning,intersections,decorations.markings,backgrounds,patterns}
\pgfplotsset{compat=newest}
\pgfplotsset{%
every axis/.append style={%
axis x line=middle,
axis y line=middle,
axis line style={-stealth, line width=0.6pt},
xlabel={$x$},ylabel={$y$},
every axis x label/.style={at={(ticklabel* cs:0.99)}, below},
every axis y label/.style={at={(ticklabel* cs:0.98)}, left},
}%
}%

\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[
declare function={
F1(\x)=-pow(\x,2);
},
enlargelimits={abs=0}, clip=false,
xmin=-6, xmax=6, ymin=-10,ymax=2,
grid=both, 
grid style={step=0.6cm, densely dashed,line width=0.1pt, draw=black!50},
xtick={-4,-2,2,4}, ytick={-8,-6,-4,-2},
x=0.6cm, y=0.6cm, domain={-4:4}, restrict y to domain={-10:4}, samples=300,
]
\addplot[draw=black,very thick] (\x,{F1(\x)}) 
node[right, pos=0.95] {$y=-x^2$}; 
\path (0,0) coordinate (O) node[above left] {O};
\end{axis}
\end{tikzpicture}
\end{document}

댓글 [2]

댓글 쓰기

목록 삭제

KTUG 한국 텍 사용자 그룹