pgfplots / gnuplot: Cách vẽ một hàm hai tham số 3D
Tôi muốn vẽ một hàm bề mặt 2 tham số
set parametric
splot cos(u)*cos(v),sin(u)*cos(v),sin(v)
(Gợi ý: Nếu tôi chỉ đặt nó vào gnuplot thì nó hoạt động.)
Tôi đoán rằng các cài đặt đặc biệt trong pgfplots là cần thiết cho một chức năng đặc biệt như vậy.
Vậy: Tại sao ví dụ thứ 2 không có gì?
Tôi phải đặt tùy chọn nào ở đây trong pgfplots?
% arara: pdflatex: {shell: yes}
\documentclass[margin=3mm, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest, width=7cm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title=Works]
\addplot3[]
gnuplot{sin(x)*sin(y)};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[font=\footnotesize,]
\begin{axis}[title={Works not - what do I have to set?}]
\addplot3[]
gnuplot {
set parametric
splot cos(u)*cos(v),sin(u)*cos(v),sin(v)
};
\end{axis}
\end{tikzpicture}
\end{document}
\end{document}
Nên cho sth. như thế này:
Trả lời
Bạn nhận được một .gnuplottệp mà bạn có thể xem để biết mã nào đang được chuyển tới Gnuplot.
Đối với trường hợp của bạn, bạn nhận được
set table "test.pgf-plot.table"; set format "%.5f"
set format "%.7e";; set samples 25, 25; set dummy x,y; set isosamples 25, 25; splot [x=-5:5] [y=-5:5] set parametric splot cos(u)*cos(v),sin(u)*cos(v),sin(v) ;
Như bạn có thể thấy splot <domain settings> <your code>, nghĩa là Gnuplot nhận được
splot ... set parametric
điều này không hoạt động vì sau splotvà các tùy chọn phải có một biểu thức hàm. Bạn cũng có thể thấy lỗi từ Gnuplot trong .logtệp, nó cho biết
"test.pgf-plot.gnuplot" line 2: undefined variable: set
nơi settrong câu hỏi là ở chỗ set parametric.
Để khắc phục điều này, bạn có thể sử dụng parametrickhóa ở phía TikZ thay vì set parametric:
% arara: pdflatex: {shell: yes}
\documentclass[margin=3mm, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest, width=7cm}
\begin{document}
\begin{tikzpicture}[font=\footnotesize,]
\begin{axis}[title={Works not - what do I have to set?}]
\addplot3[]
gnuplot [parametric=true] {
cos(u)*cos(v),sin(u)*cos(v),sin(v)
};
\end{axis}
\end{tikzpicture}
\end{document}
Hoặc bạn có thể sử dụng raw gnuplot. Trong trường hợp đó, bạn cần đặt tên miền và kích thước mẫu trong mã Gnuplot thay vì pgfplotsđược chuyển:
% arara: pdflatex: {shell: yes}
\documentclass[margin=3mm, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest, width=7cm}
\begin{document}
\begin{tikzpicture}[font=\footnotesize,]
\begin{axis}[title={Works not - what do I have to set?}]
\addplot3[]
gnuplot [raw gnuplot] {
set parametric;
splot cos(u)*cos(v),sin(u)*cos(v),sin(v)
};
\end{axis}
\end{tikzpicture}
\end{document}