如何改变 \psaxes 角度来匹配数据?

如何改变 \psaxes 角度来匹配数据?

我能够使用下面提到的 tex 代码绘制雷达图:

\documentclass[landscape,a3paper,11pt]{article}
\usepackage{pstricks-add}
\usepackage{pgfplots, pgfplotstable}
\begin{document}
\begin{center}
\begin{pspicture}(-5,-5)(5,5)
\psset{unit=1.2}
\psaxes[labels=none,axesstyle=polar,ticklinestyle=dashed,tickcolor=black!40](0,0)(-4,-4)(4,4)
\psaxes[dx=1,dy=1,Dx=25,Dy=25](0,0)(0,0)(4,4)%
\psxTick{0}(-1){25}
\psxTick{0}(-2){50}
\psxTick{0}(-3){75}
\psxTick{0}(-4){100}
\psyTick{0}(-1){25}
\psyTick{0}(-2){50}
\psyTick{0}(-3){75}
\psyTick{0}(-4){100}
\psset{fillstyle=solid,opacity=0.5}
\pswedge[fillcolor=black!10]{1}{0}{36}
\pswedge[fillcolor=black!20]{2}{36}{72}
\pswedge[fillcolor=black!30]{1}{72}{108}
\pswedge[fillcolor=black!40]{2}{108}{144}
\pswedge[fillcolor=black!50]{1}{144}{180}
\pswedge[fillcolor=black!60]{2}{180}{216}
\pswedge[fillcolor=black!70]{1}{216}{252}
\pswedge[fillcolor=black!80]{2}{252}{288}
\pswedge[fillcolor=black!90]{1}{288}{324}
\pswedge[fillcolor=black]{1}{324}{360}
\rput(4.9;18){Skill1}
\rput(4.9;54){Skill2}
\rput(4.9;90){Skill3}
\rput(4.9;126){Skill4}
\rput(4.9;162){Skill5}
\rput(4.9;198){Skill6}
\rput(4.9;234){Skill7}
\rput(4.9;270){Skill8}
\rput(4.9;306){Skill9}
\rput(4.9;342){Skill10}
\psset{opacity=1}
\end{pspicture}
\end{center}
\end{document}

生成的输出是 在此处输入图片描述

雷达图的默认轴以 30 度为间隔放置 [标记为绿色] 共有 10 个数据点,使得每个饼图的角度为 36 [即 360/10 标记为红色]

有没有办法改变雷达图的轴,使其始终与数据点的轴一致?预期轴标记为灰色

答案1

将单位设置为 300 度,但仅限于轴。如果您有多个这样的图像,则使用自己的宏\sectors{1,2,...},该宏只需要给定半径,其余部分可以由宏本身完成:

\documentclass{article}
\usepackage{pstricks-add}
\newcounter{CValue}\newcounter{GValueA}
\makeatletter
\def\sectors#1{%
  \begin{pspicture}(-5,-5)(5,5)
  \psset{unit=1.2cm}%
  \degrees[300]%
  \psaxes[labels=none,axesstyle=polar,ticklinestyle=dashed,tickcolor=black!40](0,0)(-4,-4)(4,4)
  \psaxes[dx=1,dy=1,Dx=25,Dy=25](0,0)(0,0)(4,4)%
  \degrees[360]%
  \multido{\iA=-4+1,\iB=100+-25}{4}{\psxTick{0}(\iA){\iB}\psyTick{0}(\iA){\iB}}%
  \psset{fillstyle=solid,opacity=0.5}%
  \multido{\iA=18+36,\iB=1+1}{10}{\rput(4.9;\iA){Skill\iB}}%
  \setcounter{CValue}{10}\setcounter{GValueA}{0}%
  \expandafter\sectors@i#1,,\@nil
  \end{pspicture}}
\def\sectors@i#1,#2,#3\@nil{%
  \pswedge[fillcolor=black!\theCValue]{#1}{\theGValueA}{! \theGValueA\space 36 add}%
  \ifx\relax#2\relax \else
    \addtocounter{CValue}{10}\addtocounter{GValueA}{36}%
    \sectors@i#2,#3\@nil\fi}
\makeatother
\begin{document}

\begin{center}
\sectors{1,2,1,2,1,2,1,2,1,1}
%
\sectors{1,2,3,2,1,2,3,2,1,2}
\end{center}
\end{document}

在此处输入图片描述

这是 9 个元素的解决方案。如果您经常需要,可以在宏内进行更改。但是,这里是将值 300->270 和 36->40 更改:

\documentclass{article}
\usepackage{pstricks-add}
\newcounter{CValue}\newcounter{GValueA}
\makeatletter
\def\sectors#1{%
  \begin{pspicture}(-5,-5)(5,5)
  \psset{unit=1.2cm}%
  \degrees[270]%
  \psaxes[labels=none,axesstyle=polar,ticklinestyle=dashed,tickcolor=black!40](0,0)(-4,-4)(4,4)
  \psaxes[dx=1,dy=1,Dx=25,Dy=25](0,0)(0,0)(4,4)%
  \degrees[360]%
  \multido{\iA=-4+1,\iB=100+-25}{4}{\psxTick{0}(\iA){\iB}\psyTick{0}(\iA){\iB}}%
  \psset{fillstyle=solid,opacity=0.5}%
  \multido{\iA=18+40,\iB=1+1}{9}{\rput(4.9;\iA){Skill\iB}}%
  \setcounter{CValue}{10}\setcounter{GValueA}{0}%
  \expandafter\sectors@i#1,,\@nil
  \end{pspicture}}
\def\sectors@i#1,#2,#3\@nil{%
  \pswedge[fillcolor=black!\theCValue]{#1}{\theGValueA}{! \theGValueA\space 40 add}%
  \ifx\relax#2\relax \else
    \addtocounter{CValue}{10}\addtocounter{GValueA}{40}%
    \sectors@i#2,#3\@nil\fi}
\makeatother
\begin{document}

\begin{center}
\sectors{1,2,1,2,1,2,1,2,1}
%
\sectors{1,2,3,2,1,2,3,2,1,2}
\end{center}
\end{document}

在此处输入图片描述

如果您不想修改代码,这里有解决方案:

\documentclass[landscape,a3paper,11pt]{article}
\usepackage{pstricks-add}
\usepackage{pgfplots, pgfplotstable}
\begin{document}
\begin{center}
\begin{pspicture}(-5,-5)(5,5)
\psset{unit=1.2}
\degrees[300]
\psaxes[labels=none,axesstyle=polar,ticklinestyle=dashed,tickcolor=black!40](0,0)(-4,-4)(4,4)
\psaxes[dx=1,dy=1,Dx=25,Dy=25](0,0)(0,0)(4,4)%
\degrees[360]
\multido{\iA=-4+1,\iB=100+-25}{4}{\psxTick{0}(\iA){\iB}\psyTick{0}(\iA){\iB}}
\psset{fillstyle=solid,opacity=0.5}
\pswedge[fillcolor=black!10]{1}{0}{36}
\pswedge[fillcolor=black!20]{2}{36}{72}
\pswedge[fillcolor=black!30]{1}{72}{108}
\pswedge[fillcolor=black!40]{2}{108}{144}
\pswedge[fillcolor=black!50]{1}{144}{180}
\pswedge[fillcolor=black!60]{2}{180}{216}
\pswedge[fillcolor=black!70]{1}{216}{252}
\pswedge[fillcolor=black!80]{2}{252}{288}
\pswedge[fillcolor=black!90]{1}{288}{324}
\pswedge[fillcolor=black]{1}{324}{360}
\multido{\iA=18+36,\iB=1+1}{10}{\rput(4.9;\iA){Skill\iB}}
\end{pspicture}
\end{center}
\end{document}

答案2

\documentclass[pstricks,border=13mm,11pt]{standalone}
\usepackage{pst-plot}


\begin{document}
\makeatletter
\begin{pspicture}(-5,-5)(5,5)
\psset{unit=1.2,labels=none}
\degrees[300]
\psaxes[axesstyle=polar,ticklinestyle=dashed,tickcolor=black!40](0,0)(-4,-4)(4,4)
\degrees[360]
\multido{\i=-4+1}{9}{%
    \ifnum\i>0\relax \edef\c{1} \else \edef\c{-1} \fi
    \edef\lbl{\the\numexpr\c*25*\i\relax}%
    \psxTick{0}(\i){\lbl}
    \psyTick{0}(\i){\lbl}
}
\psaxes[ticks=none](0,0)(-4,-4)(4,4)
\psset{fillstyle=solid,opacity=0.5}
\multido{\iA=0+36,\iB=36+36,\iC=10+10}{9}{%
    \pst@mod{\iC}{20}\rem
    \pswedge[fillcolor=black!\iC]{\ifnum\rem=0 2\else 1\fi}{\iA}{\iB}
}
\pswedge[fillcolor=black]{1}{324}{360}
\multido{\iA=18+36,\iB=1+1}{10}{\rput(4.9;\iA){Skill\iB}}
\end{pspicture}
\makeatother
\end{document}

在此处输入图片描述

相关内容