![PGGFlots:极坐标图的背景颜色](https://linux22.com/image/385278/PGGFlots%EF%BC%9A%E6%9E%81%E5%9D%90%E6%A0%87%E5%9B%BE%E7%9A%84%E8%83%8C%E6%99%AF%E9%A2%9C%E8%89%B2.png)
我想在 PGFPlots 中绘制所谓的“天空图”。天空图显示卫星及其在可见天空中的位置。此外,我想为一些特定的干扰绘制背景。最终它应该看起来像这样:
使用 PGFPlots 的 polaraxis 创建坐标系并放置卫星非常容易:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\newlength\figureheight
\newlength\figurewidth
\definecolor{GPS_Color}{RGB}{0, 187, 0}
\definecolor{GLO_Color}{RGB}{196, 163, 0}
\definecolor{GAL_Color}{RGB}{0, 140, 190}
\definecolor{BDS_Color}{RGB}{196, 0, 0}
\begin{document}
\scriptsize
\setlength\figureheight{\textwidth}
\setlength\figurewidth{\textwidth}
\begin{tikzpicture}
\begin{polaraxis}[
width=\figurewidth,
height=\figureheight,
rotate=-90,
axis lines*=none,
axis line style = {draw=transparent,line width=0.0001pt},
x dir=reverse,
xticklabel style={anchor=-\tick-90},
xtick={0,30,60,90,120,150,180,210,240,270,300,330},
xticklabels={N,30,60,E,120,150,S,210,240,W,300,330},
ymin=0,
ymax=90,
ytick={0,10,...,90},
yticklabels=\empty
]
\node [anchor=center,draw,circle,black,fill=GPS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:30,90-80) {\tiny{G30}};
\node [anchor=center,draw,circle,black,fill=GAL_Color,minimum size=3ex,inner sep=0pt] at (axis cs:280,90-10) {\tiny{E01}};
\node [anchor=center,draw,circle,black,fill=GLO_Color,minimum size=3ex,inner sep=0pt] at (axis cs:150,90-89) {\tiny{R13}};
\node [anchor=center,draw,circle,black,fill=BDS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:210,90-35) {\tiny{C14}};
\end{polaraxis}
\end{tikzpicture}
\end{document}
由此得出以下图表:
但是,我找不到显示背景颜色的方法。我开发了一个应用程序来计算卫星位置和背景,这就是我创建图形的方式。现在我想扩展这个应用程序以生成 tikz/pgf 代码以在 TeX 中发布。背景的颜色数据可以作为某种图像使用,因此是具有特定颜色的矩形像素阵列。但是,由于这些数据依赖于笛卡尔轴,我无法在 polaraxis 环境中直接绘制它。
如何在 PGFPlots polaraxis 环境中创建这种彩色的背景?
非常感谢。
答案1
如果您想添加背景图像(使用其他程序生成),并且您有可用的图像(无论何种格式),则可以将其添加到背景中。请注意,我过去常常scale only axis
强制极坐标图的尺寸完全符合要求的尺寸。
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\newlength\figureheight
\newlength\figurewidth
\definecolor{GPS_Color}{RGB}{0, 187, 0}
\definecolor{GLO_Color}{RGB}{196, 163, 0}
\definecolor{GAL_Color}{RGB}{0, 140, 190}
\definecolor{BDS_Color}{RGB}{196, 0, 0}
\begin{document}
\scriptsize
\setlength\figureheight{\textwidth}
\setlength\figurewidth{\textwidth}
\begin{tikzpicture}
\begin{scope}[on background layer]
\node[anchor=south west, inner sep=0pt, opacity=0.3,
] at (0,0)
{\includegraphics[width=\figurewidth,
height=\figureheight]{example-image-a}
};
\end{scope}
\begin{polaraxis}[
width=\figurewidth,
height=\figureheight,
rotate=-90,
axis lines*=none,
axis line style = {draw=transparent,line width=0.0001pt},
x dir=reverse,
xticklabel style={anchor=-\tick-90},
xtick={0,30,60,90,120,150,180,210,240,270,300,330},
xticklabels={N,30,60,E,120,150,S,210,240,W,300,330},
ymin=0,
ymax=90,
ytick={0,10,...,90},
yticklabels=\empty,
scale only axis,
]
\node [anchor=center,draw,circle,black,fill=GPS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:30,90-80) {\tiny{G30}};
\node [anchor=center,draw,circle,black,fill=GAL_Color,minimum size=3ex,inner sep=0pt] at (axis cs:280,90-10) {\tiny{E01}};
\node [anchor=center,draw,circle,black,fill=GLO_Color,minimum size=3ex,inner sep=0pt] at (axis cs:150,90-89) {\tiny{R13}};
\node [anchor=center,draw,circle,black,fill=BDS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:210,90-35) {\tiny{C14}};
\end{polaraxis}
\end{tikzpicture}
\end{document}
楼主贴出了最终结果:
答案2
在概念层面有点类似于koleygr 的回答但没有硬编码距离和更精细的颜色过渡。(编辑:使用颜色选择器来重现您的颜色,非常感谢 AndrèC!)
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\newlength\figureheight
\newlength\figurewidth
\definecolor{GPS_Color}{RGB}{0, 187, 0}
\definecolor{GLO_Color}{RGB}{196, 163, 0}
\definecolor{GAL_Color}{RGB}{0, 140, 190}
\definecolor{BDS_Color}{RGB}{196, 0, 0}
\definecolor{LEFT_Color}{RGB}{152, 205, 225}
\definecolor{RIGHT_Color}{RGB}{242, 204, 48}
\begin{document}
\scriptsize
\setlength\figureheight{\textwidth}
\setlength\figurewidth{\textwidth}
\begin{tikzpicture}
\begin{polaraxis}[
width=\figurewidth,
height=\figureheight,
rotate=-90,
axis lines*=none,
axis line style = {draw=transparent,line width=0.0001pt},
x dir=reverse,
xticklabel style={anchor=-\tick-90},
xtick={0,30,60,90,120,150,180,210,240,270,300,330},
xticklabels={N,30,60,E,120,150,S,210,240,W,300,330},
ymin=0,
ymax=90,
ytick={0,10,...,90},
yticklabels=\empty
]
\node [anchor=center,draw,circle,black,fill=GPS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:30,90-80) {\tiny{G30}};
\node [anchor=center,draw,circle,black,fill=GAL_Color,minimum size=3ex,inner sep=0pt] at (axis cs:280,90-10) {\tiny{E01}};
\node [anchor=center,draw,circle,black,fill=GLO_Color,minimum size=3ex,inner sep=0pt] at (axis cs:150,90-89) {\tiny{R13}};
\node [anchor=center,draw,circle,black,fill=BDS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:210,90-35) {\tiny{C14}};
\coordinate (c) at (axis cs:0,0);
\coordinate (aux) at (axis cs:0,90);
\coordinate (t) at (axis cs:15,90);
\coordinate (m) at (axis cs:0,40);
\coordinate (b) at (axis cs:200,90);
\end{polaraxis}
\begin{scope}[on background layer]
\clip let \p1=($(aux)-(c)$),\n1={veclen(\y1,\x1)} in (c) circle (\n1);
\fill[LEFT_Color] let \p1=($(aux)-(c)$) in (c) circle (\y1);
\path let \p1=($([xshift=-6,yshift=10]t)-(c)$),\n1={1.025*veclen(\y1,\x1)} in \pgfextra{\xdef\myrad{\n1}};
\foreach \X [evaluate=\X as \Y using {int(50+\X)}] in {-50,...,50}
{\fill[RIGHT_Color!\Y!LEFT_Color] ([xshift=0.2*\X,yshift=10]t) to[out=-120,in=70]
([xshift=0.2*\X]m) to[out=-110,in=90] ([xshift=0.2*\X,yshift=-10]b) arc(250:435:\myrad);}
\end{scope}
\end{tikzpicture}
\end{document}
即使放大很多,仍然可以实现相当平滑的过渡。
答案3
这是一种您可以自行调整颜色和“模糊”的方法:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\newlength\figureheight
\newlength\figurewidth
\definecolor{GPS_Color}{RGB}{0, 187, 0}
\definecolor{GLO_Color}{RGB}{196, 163, 0}
\definecolor{GAL_Color}{RGB}{0, 140, 190}
\definecolor{BDS_Color}{RGB}{196, 0, 0}
\definecolor{SKY_Color}{RGB}{0, 157, 210}
\begin{document}
\scriptsize
\setlength\figureheight{\textwidth}
\setlength\figurewidth{\textwidth}
\begin{tikzpicture}
\begin{polaraxis}[
width=\figurewidth,
height=\figureheight,
rotate=-90,
axis lines*=none,
axis line style = {draw=transparent,line width=0.0001pt},
x dir=reverse,
xticklabel style={anchor=-\tick-90},
xtick={0,30,60,90,120,150,180,210,240,270,300,330},
xticklabels={N,30,60,E,120,150,S,210,240,W,300,330},
ymin=0,
ymax=90,
ytick={0,10,...,90},
yticklabels=\empty
]
\end{polaraxis}
\clip (5.27,5.27) circle (5.25);
\fill[SKY_Color] (5.3,5.3) circle (5.3);
\fill[orange!50!yellow,rotate=-30, shift={(70:10)}] (1.6,-2) ellipse (4 and 6);
\draw[yellow,opacity=0.4,line width=0.2cm,rotate=-30,shift={(70:10)}] (1.6,-2) ellipse (4.05 and 6.05);
\draw[yellow,opacity=0.2,line width=0.2cm,rotate=-30,shift={(70:10)}] (1.6,-2) ellipse (4.2 and 6.2);
\draw[yellow,opacity=0.1,line width=0.2cm,rotate=-30,shift={(70:10)}] (1.6,-2) ellipse (4.3 and 6.3);
\begin{scope}
\begin{polaraxis}[
width=\figurewidth,
height=\figureheight,
rotate=-90,
axis lines*=none,
axis line style = {draw=transparent,line width=0.0001pt},
x dir=reverse,
xticklabel style={anchor=-\tick-90},
xtick={0,30,60,90,120,150,180,210,240,270,300,330},
xticklabels={N,30,60,E,120,150,S,210,240,W,300,330},
ymin=0,
ymax=90,
ytick={0,10,...,90},
yticklabels=\empty
]
\node [anchor=center,draw,circle,black,fill=GPS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:30,90-80) {\tiny{G30}};
\node [anchor=center,draw,circle,black,fill=GAL_Color,minimum size=3ex,inner sep=0pt] at (axis cs:280,90-10) {\tiny{E01}};
\node [anchor=center,draw,circle,black,fill=GLO_Color,minimum size=3ex,inner sep=0pt] at (axis cs:150,90-89) {\tiny{R13}};
\node [anchor=center,draw,circle,black,fill=BDS_Color,minimum size=3ex,inner sep=0pt] at (axis cs:210,90-35) {\tiny{C14}};
\end{polaraxis}
\end{scope}
\end{tikzpicture}
\end{document}
输出:
PS:我使用了一个以您的中心为实心的圆、一个具有适当颜色、中心/旋转的椭圆、一些用于“模糊”的椭圆,并使用您的中心和适当的半径用圆圈剪切图像。