
我對製作乳膠非常陌生,所以我發現的有關我的問題的所有教程都太難理解,或者沒有完全達到我想要的效果。
我已經有了我想要的沒有著色的圖表:
\begin{figure}
\centering
\begin{tikzpicture}
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\draw[scale=0.4,domain=-1.71:1.71,smooth,variable=\x,black] plot ({\x},{(\x)^3});
\end{tikzpicture}
\end{figure}
答案1
這是我的建議,沒有輕微的線條,因為填充的方式不同(從 AndréC 答案修改的代碼):
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip[postaction={fill=green!50}] (-2,-2) rectangle (2,2);
\fill[scale=0.4,domain=0:5,smooth,variable=\x,blue!20] plot ({\x},{(\x)^3}) |-(0,0);
\fill[scale=0.4,domain=0:-5,smooth,variable=\x,blue!20] plot ({\x},{(\x)^3}) |-(0,0);
\draw[scale=0.4,domain=-1.71:1.71,smooth,variable=\x,black] plot ({\x},{(\x)^3});
\end{scope}
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\end{tikzpicture}
\end{document}
(使用土撥鼠的有用建議編輯程式碼:用於postaction
減少冗餘程式碼。)
答案2
一個棘手的方法:
\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[blue!20] (-2,-2) rectangle (2,2);
\fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
\fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\draw[scale=0.4,domain=-1.71:1.71,smooth,variable=\x,black,fill=green!50] plot ({\x},{(\x)^3});
\end{tikzpicture}
\end{document}
編輯:
一個棘手的方法需要透過一個棘手的添加來繼續。我添加了一個line width=0mm
一行(參見這裡):
\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[blue!20] (-2,-2) rectangle (2,2);
\fill[green!50] (0,0)--({-1.71*0.4},{0.4*(-1.71^3)})--(2,-2)--(2,0)--cycle;
\fill[green!50] (0,0)--({1.71*0.4},{0.4*(1.71^3)})--(-2,2)--(-2,0)--cycle;
\draw[line width=0mm,green!50] ({1.71*0.4},{0.4*(1.71^3)})--({-1.71*0.4},{0.4*(-1.71^3)}); % <===================
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\draw[scale=0.4,domain=-1.71:1.71,smooth,variable=\x,black,fill=green!50] plot ({\x},{(\x)^3});
\end{tikzpicture}
\end{document}
我想那條很細的線已經消失了。
答案3
有了pgfplots
,這很容易做到。
這裡是純粹的tikz
DIY沒有一塊 pgfplots!
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[blue!20] (-2,-2)rectangle(2,2);
\begin{scope}[transparency group,opacity=1]
\fill[scale=0.4,domain=0:1.71,smooth,variable=\x,green] plot ({\x},{(\x)^3})coordinate(a)|-(0,0)node[midway](m){};
\fill[green](a)--(2,2)|-(m.west);
\fill[scale=0.4,domain=0:-1.71,smooth,variable=\x,green] plot ({\x},{(\x)^3})coordinate(b)|-(0,0)node[midway](n){};
\fill[green](b)--(-2,-2)|-(n.east);
\end{scope}
\draw[scale=0.4,domain=-1.71:1.71,smooth,variable=\x,black] plot ({\x},{(\x)^3});
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\end{tikzpicture}
\end{document}