我正在尝试将我一直在使用的模拟模型的输出可视化。模拟在可变半径(和可变边长)网络/图形结构上找到微分方程组的稳态解 - 例如,考虑水和溶质流过可变半径管道网络的情况。
分支中心线是直的,但沿轴向半径和其他变量(例如面积平均溶质浓度)会发生变化。
我对 pure 有基本的了解tikz
- 对 了解不多pgfplots
。到目前为止,我尝试了一种使用tikz
和pgfplotstable
(读取数据)的 hacky 解决方案,并附上了结果。
目前,我绘制每条边,执行阴影,然后旋转/平移到所需位置。我不太关心边缘是否连接良好 - 这会很好但不是必需的。我现在只是留下了空隙。我注意到阴影目前没有正确旋转 - 这不是我的主要问题,因为我已经看到了几种方法来实现这一点,但我有点担心使用画布变换的复杂性,因为我还需要对每条边进行大量平移和不同的旋转。还要注意,我对数据的读取非常不规范,因为我使用纯数据进行绘图tikz
并想要一条平滑的曲线。可能有更好的解决方案……
我遇到的最困难的问题是,我希望颜色根据从外部文件读取的数据而变化 - 例如,表示沿给定边缘的局部轴向坐标处的溶质浓度。我见过一个使用“功能着色”的 tikz 示例(http://www.texample.net/tikz/examples/hsv-shading/),但它看起来非常复杂。我想知道 pgfplots 是否可能是更好的选择,例如,我见过人们提到“colormap”图,但我不确定我是否仍然能够轻松地绘制网络结构,或者我是否可以将它与一些纯 tikz 等一起使用。
所以,我的问题实际上是如何最好地结合所有可用的工具来tikz
实现pgfplots
我想要的一切。我可以用一些工具来实现,tikz
但可能不是全部,我不确定是否pgfplots
可以解决这些问题,或者我应该找到另一种方法。任何建议都将不胜感激。
[啊,我意识到我无法发布图片,因为我是 StackExchange 新手。我已注释掉图片。如果这让我的问题更难理解,我很抱歉!]
示例代码:
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}[scale=5]
\pgfplotstableread[header=true,x=localcoord,y=radius]{coord2.dat}{\data}
\pgfplotstablegetrowsof{\data}
\pgfmathsetmacro{\rowindex}{\pgfplotsretval-1}
%-variables to build curves
\gdef\currentpath{}
\gdef\currentcoordlist{}
%-read data
\foreach \srowindex in {0,...,\rowindex}{
%--get first coord pair
\pgfplotstablegetelem{\srowindex}{localcoord}\of{\data}
\pgfmathsetmacro{\x}{\pgfplotsretval}
\pgfplotstablegetelem{\srowindex}{radius}\of{\data}
\pgfmathsetmacro{\y}{\pgfplotsretval}
%--concatenate
\global\edef\currentpath{\currentpath--(\x,\y)}
\global\edef\currentcoordlist{\currentcoordlist (\x,\y)}
}
\begin{scope}[rotate around = {-90:(1,1)},shift={(1,1)}]
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth] coordinates \currentcoordlist;
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\draw plot[smooth] coordinates \currentcoordlist;
\draw plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\end{scope}
\begin{scope}[rotate around = {-45:(1,0)},shift={(1,0)}]
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth] coordinates \currentcoordlist;
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\draw plot[smooth] coordinates \currentcoordlist;
\draw plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\end{scope}
\begin{scope}[rotate around = {-90:(1.707,-0.707)},shift={(1.707,-0.707)}]
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth] coordinates \currentcoordlist;
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\draw plot[smooth] coordinates \currentcoordlist;
\draw plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\end{scope}
\begin{scope}[rotate around = {-135:(2.41,0)},shift={(2.41,0)}]
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth] coordinates \currentcoordlist;
\path[fill,top color=blue, bottom color= green] (0.85,0)--(0,0) -- plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\draw plot[smooth] coordinates \currentcoordlist;
\draw plot[smooth,yscale={-1}] coordinates \currentcoordlist;
\end{scope}
\end{tikzpicture}
\end{document}
数据文件coord2.dat
::
localcoord radius
0.0 0.1
0.1 0.1
0.2 0.15
0.3 0.1
0.4 0.2
0.5 0.1
0.6 0.05
0.7 0.15
0.8 0.1
0.85 0.1
%1.0 0.15
答案1
我知道一个关键要求是阴影从中心线(对称)扩展到边界,对吗?
这可以通过 pgfplots 的补丁图与shader=interp
pgfplots 结合来实现:
\documentclass{standalone}
\usepackage{pgf,tikz,pgfplots,pgfplotstable}
% for patch type=bilinear
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}[scale=5]
\pgfplotstableread[header=true,x=localcoord,y=radius]{coord2.dat}{\data}
\pgfplotstablegetrowsof{\data}
\pgfmathsetmacro{\rowindex}{\pgfplotsretval-1}
%-variables to build curves
\gdef\currentpath{}
\gdef\currentcoordlist{}
\gdef\Cim{}
\gdef\Rim{}
%-read data
% R_{i-1} C_{i-1}
% Ri Ci
%
% and transform each two successive coords to TWO rectangular patches
% which have color data in square brackets
%
%
\foreach \srowindex in {0,...,\rowindex}{
%--get first coord pair
\pgfplotstablegetelem{\srowindex}{localcoord}\of{\data}
\pgfmathsetmacro{\Ci}{\pgfplotsretval}
\pgfplotstablegetelem{\srowindex}{radius}\of{\data}
\pgfmathsetmacro{\Ri}{\pgfplotsretval}
%--concatenate
\ifx\Cim\empty
\else
\def\cdataim{1}%
\def\cdatai{1}%
% \def\cdataim{\Rim}%
% \def\cdatai{\Ri}%
\global\edef\currentcoordlist{\currentcoordlist
(\Cim,\Rim) [\cdataim] (\Cim,0) [0]
(\Ci,0) [0] (\Ci,\Ri) [\cdatai]
}%
\global\edef\currentcoordlist{\currentcoordlist
(\Cim,-\Rim) [\cdataim] (\Cim,0) [0]
(\Ci,0) [0] (\Ci,-\Ri) [\cdatai]
}%
\fi
\global\let\Cim=\Ci
\global\let\Rim=\Ri
}
\global\edef\currentcoordlist{%
\noexpand\addplot[
shader=interp,
patch,
% patch type=rectangle,
patch type=bilinear,
mark=*,
]
coordinates {\currentcoordlist};
}%
\message{I got \meaning\currentcoordlist^^J}%
\def\image{%
\begin{axis}[
clip=false,
hide axis,
point meta=explicit,
x=1cm,
y=1cm,
mark size=0.05pt,
anchor=origin,
]
\currentcoordlist
\end{axis}
}%
\begin{scope}[rotate around = {-90:(1,1)},shift={(1,1)}]
\image
\end{scope}
\begin{scope}[rotate around = {-45:(1,0)},shift={(1,0)}]
\image
\end{scope}
\end{tikzpicture}
\end{document}
关键思想是创建矩形块。更准确地说,对于每两个连续的输入坐标,它都会创建两个矩形块。这些矩形块的坐标必须按特定顺序提供(即绘制其边界的顺序)。坐标后的方括号是颜色数据:标量值,用于标识该点的颜色。为了获得“正确”的颜色,它被映射到当前colormap
。在我的解决方案中,中心的 cdata 始终为 0,而边缘的 cdata 始终为 1。
编辑这是具有更平滑边界曲线的替代方法。它试图在 pgfpltos 的当前功能集下以最小的努力获得与平滑边界类似的效果。
它使用双二次着色,每个着色由三个连续的输入点组成。更准确地说,点 0、1、2 组成第一个双二次补丁,点 2、3、4 组成第二个双二次补丁,依此类推。这允许分段二次边界。然而,由于大小为 3 的组不相关,因此在寓言连接处仍然存在尖锐的边缘:
\documentclass{standalone}
\usepackage{pgf,tikz,pgfplots,pgfplotstable}
% for patch type=bilinear
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}[scale=5]
\pgfplotstableread[header=true,x=localcoord,y=radius]{
localcoord radius
0.0 0.1
0.1 0.1
0.2 0.15
0.3 0.1
0.4 0.2
0.5 0.1
0.6 0.05
0.7 0.15
0.8 0.1
0.9 0.1
1.0 0.15
}{\data}
\pgfplotstablegetrowsof{\data}
\pgfmathsetmacro{\rowindex}{\pgfplotsretval-1}
%-variables to build curves
\gdef\currentpath{}
\gdef\currentcoordlist{}
\gdef\Cimm{}
\gdef\Rimm{}
\gdef\Cim{}
\gdef\Rim{}
%-read data
% R_{i-1} C_{i-1}
% Ri Ci
%
% and transform each two successive coords to TWO rectangular patches
% which have color data in square brackets
%
%
\gdef\srowindexmodthree{0}
\foreach \srowindex in {0,...,\rowindex}{
%--get first coord pair
\pgfplotstablegetelem{\srowindex}{localcoord}\of{\data}
\pgfmathsetmacro{\Ci}{\pgfplotsretval}
\pgfplotstablegetelem{\srowindex}{radius}\of{\data}
\pgfmathsetmacro{\Ri}{\pgfplotsretval}
%--concatenate
\ifnum\srowindexmodthree=2
\def\cdataimm{1}%
\def\cdataim{1}%
\def\cdatai{1}%
% \def\cdataim{\Rim}%
% \def\cdatai{\Ri}%
%
% (C[i-2], R[i-2]) (C[i-2],R[i-2]/2) (C[i-2],0)
%
% (C[i-1], R[i-1]) (C[i-1], R[i-1]/2)) (C[i-1],0)
%
% (C[i], R[i]) (C[i],R[i]/2) (C[i], 0)
%
% in sequence
% 0 4 1
%
% 7 8 5
%
% 3 6 2
\global\edef\currentcoordlist{\currentcoordlist
(\Cimm,\Rimm) [\cdataimm]
(\Cimm,0) [0]
(\Ci,0) [0]
(\Ci,\Ri) [\cdatai]
%
(\Cimm,\Rimm/2) [0.5]
(\Cim,0) [0]
(\Ci,\Ri/2) [0.5]
(\Cim,\Rim) [\cdataim]
%
(\Cim,\Rim/2) [0.5]
}%
\global\edef\currentcoordlist{\currentcoordlist
(\Cimm,-\Rimm) [\cdataimm]
(\Cimm,0) [0]
(\Ci,0) [0]
(\Ci,-\Ri) [\cdatai]
%
(\Cimm,-\Rimm/2) [0.5]
(\Cim,0) [0]
(\Ci,-\Ri/2) [0.5]
(\Cim,-\Rim) [\cdataim]
%
(\Cim,-\Rim/2) [0.5]
}%
\fi
\global\let\Cimm=\Cim
\global\let\Rimm=\Rim
\global\let\Cim=\Ci
\global\let\Rim=\Ri
\count2=\srowindexmodthree\relax
\advance\count2 by1
\ifnum\count2=3
\count2=1 % do not start by 0, we reuse the first vertex
\fi
\xdef\srowindexmodthree{\the\count2 }%
}
\global\edef\currentcoordlist{%
\noexpand\addplot[
shader=interp,
patch,
% patch type=rectangle,
patch type=biquadratic,
mark=*,
]
coordinates {\currentcoordlist};
}%
\message{I got \meaning\currentcoordlist^^J}%
\def\image{%
\begin{axis}[
clip=false,
hide axis,
point meta=explicit,
x=1cm,
y=1cm,
mark size=0.05pt,
anchor=origin,
]
\currentcoordlist
\end{axis}
}%
\begin{scope}[rotate around = {-90:(1,1)},shift={(1,1)}]
\image
\end{scope}
\end{tikzpicture}
\end{document}
该方法稍微复杂一些,因为它会按特定顺序重新组合输入坐标。此外,只有输入坐标的数量合适时,该方法才有效(我从您的数据文件中添加了另一个要点)。
最后说明一下:标记是可选的;如果用 取消注释该行,则可以禁用它们mark=*
。
答案2
关于我对 Christian 的回答的评论,这是我目前得出的部分答案。我基本上绘制一个矩形色块,然后使用堆叠图在顶部绘制弯曲区域,并使用白色填充删除我不想要的色块图部分。图堆叠意味着在单独的轴上执行最容易(我认为?)。剩下的主要事情是保持图的正确分组和叠加。我想这应该不会太难,但我并不 100% 知道如何最好地定位各种图/轴。背景颜色的轮廓会/不会显示取决于不同的查看器,但我想我可以更小心地定义修补区域/覆盖。
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.7}
\begin{document}
\pgfplotstableread[header=true,x=localcoord,y=radius]{
localcoord radius
0.0 0.1
0.1 0.1
0.2 0.15
0.3 0.1
0.4 0.2
0.5 0.1
0.6 0.05
0.7 0.15
0.8 0.1
0.9 0.1
%1.0 0.15
}{\data}
\begin{tikzpicture}[scale=2]
%-coloured tube
%colouring
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,point meta=explicit]%,colorbar];
\addplot[patch,patch type=rectangle,shader=interp] coordinates {(0,-0.5) [1] (0.9,-0.5) [20] (0.9,0.5) [20] (0,0.5) [1]};
\end{axis}
%upper part
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,point meta=explicit,area style,stack plots=y]
\addplot[smooth,draw=none] table[x=localcoord,y=radius] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%lower part
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,point meta=explicit,area style,stack plots=y]
\addplot[smooth,draw=none] table[x=localcoord,y expr=-\thisrow{radius}] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=\thisrow{radius}-0.5] {\data} \closedcycle;
\end{axis}
%outline
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5]
\addplot[smooth] table[x=localcoord,y=radius] {\data};
\addplot[smooth] table[x=localcoord,y expr=-\thisrow{radius}] {\data};
\end{axis}
%-rotated coloured tube
%colouring
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,point meta=explicit,transform canvas={rotate =60}]%,colorbar];
\addplot[patch,patch type=rectangle,shader=interp] coordinates {(0,-0.5) [1] (0.9,-0.5) [20] (0.9,0.5) [20] (0,0.5) [1]};
\end{axis}
%upper part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,point meta=explicit,area style,stack plots=y,transform canvas={rotate =60}]
\addplot[smooth,draw=none] table[x=localcoord,y=radius] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%lower part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,point meta=explicit,area style,stack plots=y,transform canvas={rotate =60}]
\addplot[smooth,draw=none] table[x=localcoord,y expr=-0.5] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%outline of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=-0.5, xmax= 1.5,ymin=-0.5,ymax=1.5,transform canvas={rotate =60}]
\addplot[smooth] table[x=localcoord,y=radius] {\data};
\addplot[smooth] table[x=localcoord,y expr=-\thisrow{radius}] {\data};
\end{axis}
\end{tikzpicture}
\end{document}
编辑
这是具有相对定位的更新版本。我需要整理各种图的一些层次,并完全实现网络结构和数据的读取,但我认为这对我来说最有效。如果有人有任何建议让它变得更好,我会很高兴听到!
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.7}
\begin{document}
\pgfplotstableread[header=true,x=localcoord,y=radius]{
localcoord radius
%0.0 0.1
0.1 0.08
0.2 0.15
0.3 0.1
0.4 0.19
0.5 0.1
0.6 0.05
0.7 0.15
0.8 0.1
0.9 0.1
%1.0 0.15
}{\data}
\begin{tikzpicture}[x=100,y=100]
%nodes for connections
\draw (0,0) node[shape=circle,draw]{1};
\draw (1,-1.41) node[shape=circle,draw]{2};
\draw (1,0) node[shape=circle,draw]{3};
\draw (1.71,-0.71) node[shape=circle,draw]{4};
\draw (2.71,-0.71) node[shape=circle,draw]{5};
%-horizontal coloured tube
\begin{scope}[rotate around = {0:(0,0)},shift={(0,0)}]
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,at={(0,0)},anchor=origin]%,colorbar];,transform canvas={rotate =60}
\addplot[patch,patch type=rectangle,shader=interp] coordinates {(0.1,-0.2) [1] (0.9,-0.2) [20] (0.9,0.2) [20] (0.1,0.2) [1]};
\end{axis}
%upper part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y=radius] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%lower part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y expr=-0.2] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.2] {\data} \closedcycle;
\end{axis}
%outline of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,at={(0,0)},anchor=origin]
\addplot[smooth] table[x=localcoord,y=radius] {\data};
\addplot[smooth] table[x=localcoord,y expr=-\thisrow{radius}] {\data};
\end{axis}
\end{scope}
%-rotated coloured tube
%colouring
\begin{scope}[rotate around = {-45:(1,0)},shift={(1,0)}]
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,at={(0,0)},anchor=origin]%,colorbar];,transform canvas={rotate =60}
\addplot[patch,patch type=rectangle,shader=interp] coordinates {(0.1,-0.2) [1] (0.9,-0.2) [20] (0.9,0.2) [20] (0.1,0.2) [1]};
\end{axis}
%upper part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y=radius] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%lower part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y expr=-0.2] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.2] {\data} \closedcycle;
\end{axis}
%outline of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,at={(0,0)},anchor=origin]
\addplot[smooth] table[x=localcoord,y=radius] {\data};
\addplot[smooth] table[x=localcoord,y expr=-\thisrow{radius}] {\data};
\end{axis}
\end{scope}
%-rotated coloured tube 2
%colouring
\begin{scope}[rotate around = {45:(1,-1.41)},shift={(1,-1.41)}]
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,at={(0,0)},anchor=origin]%,colorbar];,transform canvas={rotate =60}
\addplot[patch,patch type=rectangle,shader=interp] coordinates {(0.1,-0.2) [1] (0.9,-0.2) [20] (0.9,0.2) [20] (0.1,0.2) [1]};
\end{axis}
%upper part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y=radius] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%lower part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y expr=-0.2] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.2] {\data} \closedcycle;
\end{axis}
%outline of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,at={(0,0)},anchor=origin]
\addplot[smooth] table[x=localcoord,y=radius] {\data};
\addplot[smooth] table[x=localcoord,y expr=-\thisrow{radius}] {\data};
\end{axis}
\end{scope}
%-horizontal coloured tube 2
\begin{scope}[rotate around = {0:(0,0)},shift={(1.71,-0.71)}]
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,at={(0,0)},anchor=origin]%,colorbar];,transform canvas={rotate =60}
\addplot[patch,patch type=rectangle,shader=interp] coordinates {(0.1,-0.2) [1] (0.9,-0.2) [20] (0.9,0.2) [20] (0.1,0.2) [1]};
\end{axis}
%upper part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y=radius] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.5] {\data} \closedcycle;
\end{axis}
%lower part of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,point meta=explicit,area style,stack plots=y,at={(0,0)},anchor=origin]
\addplot[smooth,draw=none] table[x=localcoord,y expr=-0.2] {\data} -- (axis cs:0.9,0) \closedcycle;
\addplot[smooth,fill=white,color=white] table[x=localcoord,y expr=-\thisrow{radius}+0.2] {\data} \closedcycle;
\end{axis}
%outline of tube
\begin{axis}[hide axis,x=100,y=100,z=100,xmin=0, xmax= 1,ymin=-0.2,ymax=0.2,at={(0,0)},anchor=origin]
\addplot[smooth] table[x=localcoord,y=radius] {\data};
\addplot[smooth] table[x=localcoord,y expr=-\thisrow{radius}] {\data};
\end{axis}
\end{scope}
\end{tikzpicture}
\end{document}