그래프가 여기서 위로 이동하는 이유는 무엇입니까?

그래프가 여기서 위로 이동하는 이유는 무엇입니까?

아래 그래프에 방정식 x+y-30을 사용하여 반투명 수직 빨간색 구분선을 추가하고 싶습니다. 곡선을 두 부분으로 잘라야 합니다.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.17}
\begin{document}
    \begin{tikzpicture}
        \begin{axis} [
            xtick = {0,20,...,100},
            ytick = {0,20,...,60},
            ztick = {0,40,...,120},
            xlabel = $U_A$, ylabel = $U_B$, zlabel = $S$,
            zlabel style={rotate=-90},
            ticklabel style = {font = \scriptsize},
            colormap/cool
            ]
            \addplot3[name path=toppath, domain=0:30, fill=blue, opacity=0.1, fill opacity=0.4,samples=30] (x,30-x,120);
            \addplot3[name path=botpath, domain=0:30, fill=blue, opacity=0.1, fill opacity=0.4,samples=30] (x,30-x,0);
            \addplot [red] fill between[of=toppath and botpath];
            \addplot3 [surf, shader=interp, domain=0:100, domain y=0:60, samples=56]
            { ln((100!/(x!*(100-x)!))*(60!/(y!*(60-y)!))) };
        \end{axis}
    \end{tikzpicture}
\end{document}

코드를 실행하면 이상한 결과가 나타납니다.

원래 곡선이 위쪽으로 이동하는 이유를 이해할 수 없습니다.

내가 보고 싶은 건 바로 이것이다

(또한 보기를 바꾸는 가장 좋은 방법이 무엇인지 궁금합니다. 보기 상자 왼쪽 모서리의 관점에서 그래프를 보고 싶습니다.)

답변1

안타깝게도 이러한 종류의 오버레이는 아직 pgfplots. 유일한 해결책은 표면의 여러 부분을 개별적으로 플롯하는 것입니다. 이 경우 교차 평면의 경우 올바른 순서로 올바르게 겹치도록 합니다. 직사각형이 아닌 영역에 함수를 그리려면 사용하려는 영역을 매개변수화해야 합니다. 이 경우 위에서 보면 삼각형과 다각형이 있습니다.

여기에 이미지 설명을 입력하세요

정점이 주어지면 삼각형을 매개변수화하는 것은 간단하지만 다각형의 경우 복잡할 수 있습니다. 가장 간단한 해결책은 다각형을 추가 삼각형으로 나누는 것입니다. 여기에 이미지 설명을 입력하세요

p13개의 정점 , p2및 가 주어지면 삼각형을 매개변수화하려면 p3다음 매개변수화를 사용할 수 있습니다.

eq1

eq2

값을 얻었으므로 이제 모든 표면을 플롯하여 완전한 표면을 얻을 수 있습니다. 또한 샘플링 속도를 높게 설정해야 합니다. 그렇지 않으면 낮은 품질의 렌더링으로 인해 가장자리의 불규칙성이 부분 표면의 접합부 사이에 틈을 발생시킬 수 있습니다. 이것은 매우 까다로운 솔루션이므로 아래에는 shell-escape옵션을 사용한 코드와 결과 그래프 gnuplot도 있습니다.

다음만 사용 pgfplots:

\documentclass[border=10pt]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

    \begin{tikzpicture}
        \begin{axis} [
            xtick = {0,20,...,100},
            ytick = {0,20,...,60},
            ztick = {0,40,...,120},
            xlabel = $U_A$, ylabel = $U_B$, zlabel = $S$,
            zlabel style={rotate=-90},
            ticklabel style = {font = \scriptsize},
            colormap/cool,
            variable=s,
            variable y=t,
            domain=0:1,
            view/h=15,
            ]   
\addplot3 [surf, shader=interp, samples=80, samples y=80] ({100-100*s},{-30*s-30*t*s+60},{ ln((100!/(x!*(100-x)!))*(60!/(y!*(60-y)!))) }); %B
                         
\addplot3 [surf,shader=interp, samples=30, samples y=30,] ({100*t*s+30-30*s},{30*s+30*t*s},{ ln((100!/(x!*(100-x)!))*(60!/(y!*(60-y)!))) }); %C
                      
\addplot3 [surf, shader=interp, samples=30, samples y=30,] ({100+70*t*s-70*s},{60*t*s},{ ln((100!/(x!*(100-x)!))*(60!/(y!*(60-y)!))) }); %D
             
\addplot3 [patch, fill=red, patch type=rectangle] coordinates {(0,30,120) (30,0,120)  (30,0,0) (0,30,0)};
                        
\addplot3 [surf, shader=interp, samples=30, samples y=30] ({30-30*s},{30*s*t},{  ln((100!/(x!*(100-x)!))*(60!/(y!*(60-y)!))) }); %A
                          
       \end{axis}
    \end{tikzpicture}
    
\end{document}

여기에 이미지 설명을 입력하세요

pgfplots및 사용 gnuplot:

\documentclass[border=10pt, convert={true}]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

    \begin{tikzpicture}
        \begin{axis} [
            xtick = {0,20,...,100},
            ytick = {0,20,...,60},
            ztick = {0,40,...,120},
            xlabel = $U_A$, ylabel = $U_B$, zlabel = $S$,
            zlabel style={rotate=-90},
            ticklabel style = {font = \scriptsize},
            colormap/cool,
            view/h=15,
            ]   
            
           \addplot3[surf, shader=interp, thick ]  gnuplot [ raw gnuplot, id=B ]  {
           set samples 60,60; 
           set isosamples 60,60;
           set parametric; 
           fx(u,v)=100-100*u; 
           fy(u,v)=-30*u-30*v*u+60; 
           fz(u,v)= log((100!/((int((100-100*u)))!*(100-int((100-100*u)))!))*(60!/((int((-30*u-30*v*u+60)))!*(60-int((-30*u-30*v*u+60)))!)));
           splot [0:1][0:1] fx(u,v), fy(u,v), fz(u,v)}; %B
           
            \addplot3[surf, shader=interp]  gnuplot [ raw gnuplot, id=C]  {
           set samples 60,60; 
           set isosamples 60,60;
           set parametric;
           gx(u,v)=100*v*u+30-30*u; 
           gy(u,v)=30*u+30*v*u; 
           gz(u,v)= log((100!/((int(100*v*u+30-30*u))!*(100-int(100*v*u+30-30*u))!))*(60!/((int(30*u+30*v*u))!*(60-int(30*u+30*v*u))!)));
           splot [0:1][0:1] gx(u,v), gy(u,v), gz(u,v) }; %C
           
           \addplot3[surf, shader=interp]  gnuplot [ raw gnuplot, id=D]  {
    set samples 60,60; 
    set isosamples 60,60;
           set parametric;
           hx(u,v)=100+70*v*u-70*u; 
           hy(u,v)= 60*v*u; 
           hz(u,v)=log((100!/((int(100+70*v*u-70*u))!*(100-int(100+70*v*u-70*u))!))*(60!/((int(60*v*u))!*(60-int(60*v*u))!)));
           splot [0:1][0:1] hx(u,v), hy(u,v), hz(u,v) }; %D

                        \addplot3 [patch, fill=red, patch type=rectangle] coordinates {(0,30,120) (30,0,120)  (30,0,0) (0,30,0)};
                        
                        \addplot3[surf, shader=interp]  gnuplot [raw gnuplot, id=A ]  {
                        set samples 60,60; 
                        set isosamples 60,60;
                        set parametric; 
                        splot [0:1][0:1] 30-30*u,30*u*v,log((100!/((int(30-30*u))!*(100-int(30-30*u))!))*(60!/((int(30*u*v))!*(60-int(30*u*v))!)))   }; %A
            
             
       \end{axis}
    \end{tikzpicture}
    
\end{document}

여기에 이미지 설명을 입력하세요

뷰를 변경하려면 view/h= angle옵션을 사용할 수 있습니다. 이때 올바른 겹침을 달성하기 위해 그에 따라 표면의 순서를 조정해야 합니다.

두 가지 방법의 렌더링에는 약간의 차이가 있습니다. 더 나은 결과를 얻을 수는 없었지만 더 나은 조합을 찾을 수 있는지 자유롭게 샘플링을 조정해 보세요.

관련 정보