我有以下绘制轮廓的代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\pgfplotsset{compat=newest}
\pgfplotsset{
colormap={parula}{
rgb255=(53,42,135)
rgb255=(15,92,221)
rgb255=(18,125,216)
rgb255=(7,156,207)
rgb255=(21,177,180)
rgb255=(89,189,140)
rgb255=(165,190,107)
rgb255=(225,185,82)
rgb255=(252,206,46)
rgb255=(249,251,14)
},
}
\begin{document}
\begin{tikzpicture}[
/pgf/declare function={
func(\x, \y) = 0.5*sin( deg(pi/2*(2*( \x*cos(30) - \y*sin(30) )-( \y*cos(30) + \x*sin(30) ))) ) + 2*( \y*cos(30) + \x*sin(30) ) + 1;
}
]
\begin{axis}[set layers,colorbar,
view={0}{90},
xmin=-1, xmax=1,
ymin=-1, ymax=1,
xtick={-1,-0.5,0,0.5,1},
ytick={-1,-0.5,0,0.5,1},
axis on top=false,
grid=major,
]
\addplot3[domain=-1:1, y domain=-1:1, samples=51,thick,
contour gnuplot={levels={-0.891997534235677,-0.47155363773886,-0.0511097412420427,0.369334155254774,0.789778051751592,1.21022194824841,1.63066584474523,2.05110974124204,2.47155363773886,2.89199753423568},labels=false}
]
{func(x,y)};
\addplot3[domain=-1:1, y domain=-1:1, samples=51,thick,
contour gnuplot={levels={-1,3},labels=false,fill opacity=0}
]
{func(x,y)};
\end{axis}
\end{tikzpicture}
\end{document}
我在输出值 $z=-1$ 和 $z=3$ 处创建了两个轮廓,以便颜色条显示介于这两个值之间的范围。但我的目的是通过将其不透明度设置为 0 来使这些轮廓不可见。但是,我尝试了draw opacity=0
、opacity=0
和fill opacity=0
,它们对这两条曲线都没有任何影响。
我已经阅读了 PGFPLOTS 手册,希望其中有关于不透明度选项的参考,gnuplot contour
但我没有找到这个
编辑:我最终找到了解决问题的方法,在这里解决。但是,问题的实质仍然存在。如何改变轮廓的不透明度?
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfplotsset{
colormap={parula}{
rgb255=(53,42,135)
rgb255=(15,92,221)
rgb255=(18,125,216)
rgb255=(7,156,207)
rgb255=(21,177,180)
rgb255=(89,189,140)
rgb255=(165,190,107)
rgb255=(225,185,82)
rgb255=(252,206,46)
rgb255=(249,251,14)
},}
\begin{document}
\begin{tikzpicture}[
declare function={func(\x, \y) = 0.5*sin( deg(pi/2*(2*( \x*cos(30) - \y*sin(30) )-( \y*cos(30) + \x*sin(30) ))) ) + 2*( \y*cos(30) + \x*sin(30) ) + 1;}
]
\begin{axis}[
colorbar, point meta min=-1, point meta max=3,
view={0}{90},
xmin=-1, xmax=1,
ymin=-1, ymax=1,
xtick distance=0.5, ytick distance=0.5,
grid=major,
]
\addplot3[
domain=-1:1, y domain=-1:1, samples=11, thick,
contour gnuplot={levels={-0.891997534235677,-0.47155363773886,-0.0511097412420427,0.369334155254774,0.789778051751592,1.21022194824841,1.63066584474523,2.05110974124204,2.47155363773886,2.89199753423568}, labels=false},
] {func(x,y)};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:我没有看到您关于已经解决问题的评论。以下是如何将不透明度设置为零:
\addplot3[
domain=-1:1, y domain=-1:1, samples=11, thick, opacity=0,
contour gnuplot={levels={-1,3},labels=false},
] {func(x,y)};