그리드 선의 색상을 변경하는 방법과 눈금 선의 위치를 ​​변경하는 방법은 무엇입니까?

그리드 선의 색상을 변경하는 방법과 눈금 선의 위치를 ​​변경하는 방법은 무엇입니까?

아래 두 함수 사이의 영역을 표시하는 코드를 작성 중입니다. 좋은 일이지만 더 좋아질 수 있습니다.

영상

내 질문은: 지침이 교차하지 않도록 x 눈금 레이블(x축의 숫자)을 약간 왼쪽으로 이동하는 방법이 있습니까? 또한 y-틱 레이블(조금 아래)에도 동일한 작업을 수행합니까? 가이드라인 그리드 매트릭스의 가이드라인 색상과 x 및 y 간격을 어떻게 변경할 수 있나요?

\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{fillbetween}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}
% Eixos
\begin{axis}[
grid,
axis x line=center,
axis y line=center,
xtick={-1,0,1},
ytick={-1,0,1},
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-0.5,
xmax=1.1,
ymin=-0.5,
ymax=1.1]

% Função de cima contínua
\addplot[name path=f,domain=0:1,CCazul] {x};
% Função de baixo cintínua
\addplot[name path=g,domain=0:1,CCvermelho] {x^2};

% Função de cima pontilhada
\addplot[dashed, name path=fpont1,domain=-.5:0,CCazul] {x};
\addplot[dashed, name path=fpont2,domain=1:1.1,CCazul] {x};
% Função de baixo pontilhada
\addplot[dashed, name path=gpont1,domain=-.5:0,CCvermelho] {x^2};    
\addplot[dashed, name path=gpont2,domain=1:1.1,CCvermelho] {x^2};   

% Path
\path[name path=axis] (axis cs:0,0) -- (axis cs:1,0);

%Fill between
\addplot [
thick,
color=black,
fill=black, 
fill opacity=0.05
]
fill between[
of=f and g,
soft clip={domain=0:1},
];

% Labels dos nós
\node [color=CCazul] at (axis cs:  .55,  .8) {$f(x) = x$};
\node  [color=CCvermelho] at (axis cs:  0.9,  .4) {$g(x) = x^2$};
\end{axis}
\end{tikzpicture}

\end{document}

감사합니다.

답변1

xticklabel style={below left}y축과 마찬가지로 x 눈금 레이블을 오프셋하도록 지정할 수 있습니다 .

격자선 모양을 변경하려면 를 지정합니다 grid style={...}.

그리드 선 사이의 간격을 변경하려면 둘 다의 간격이 동일하지 않은 경우 , minor tick numminor x tick num를 지정할 수 있습니다.minor y tick num

예( 이 색상의 정의를 생략했기 때문에 및로 변경 CCazul했습니다 ) :blueCCvermelhored

\documentclass[tikz]{standalone}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid=both,
grid style={red!15},
axis x line=center,
axis y line=center,
xtick={-1,0,1},
ytick={-1,0,1},
minor tick num=4,
xticklabel style={below left},
yticklabel style={below left},
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-0.5,
xmax=1.1,
ymin=-0.5,
ymax=1.1]

\addplot[name path=f,domain=0:1,blue] {x};

\addplot[name path=g,domain=0:1,red] {x^2};

\addplot[dashed, name path=fpont1,domain=-.5:0,blue] {x};
\addplot[dashed, name path=fpont2,domain=1:1.1,blue] {x};

\addplot[dashed, name path=gpont1,domain=-.5:0,red] {x^2};    
\addplot[dashed, name path=gpont2,domain=1:1.1,red] {x^2};   

% Path
\path[name path=axis] (axis cs:0,0) -- (axis cs:1,0);

%Fill between
\addplot [
thick,
color=black,
fill=black, 
fill opacity=0.05
]
fill between[
of=f and g,
soft clip={domain=0:1},
];

\node[blue] at (axis cs:  .55,  .8) {$f(x) = x$};
\node[red] at (axis cs:  0.9,  .4) {$g(x) = x^2$};
\end{axis}
\end{tikzpicture}
\end{document}

산출

관련 정보