如何为四象限功率图添加背景颜色?

如何为四象限功率图添加背景颜色?

我拼凑了以下图画。这使得标记区域的颜色非常困难:

1.xx、2.xx、3.xx、4.xx、5.xx、6.xx、7.xx 和 8.xx。

本质上,我想知道如何为光盘或由线条和圆弧构成的封闭形状添加背景颜色。

图表如下:

在此处输入图片描述

被黑的Beamer代码如下:

\documentclass[handout,
 10pt]{beamer}
\usepackage{pgfpages}
%\pgfpagesuselayout{2 on 1}[landscape,a4paper,border shrink=5mm]\pgfpageslogicalpageoptions{1}{border code=\pgfusepath{stroke}}\pgfpageslogicalpageoptions{2}{border code=\pgfusepath{stroke}}

\def\pgfsysdriver{pgfsys-dvipdfm.def}
%
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}



%
%  Use a proper sans serif font
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{bm}
\usepackage{xspace}
\usepackage{romanbar}
%\usepackage{amsmath}

\usepackage{siunitx}
%
%  Proper use of ISO 8601 dates
%
%%%%%%%%%%%%%%%%%%%%%%%%%%



%
%  Use fake small caps (better definition required}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{relsize}
\newcommand\fakesc[1]{{\relscale{0.8}\MakeUppercase{#1}}}
\renewcommand\textsc[1]{{\fakesc{#1}}}



%\usepackage{longtable}
%\usepackage{lscape}



\usepackage[iso,english]{isodate}
%\renewcommand*\date[1]{{\isodate{#1}}}

\usepackage{steinmetz}% for \phasor{t}

\usepackage[UKenglish]{babel}

%\usepackage{hyperref}%
%\hypersetup{pdfstartview=FitH,pdfremotestartview=FitH,pdftitle={Meter Calibration Report},
%pdfauthor={C Malan},pdfsubject={Meter Number 3501876543219},pdfkeywords={3501876543219}}

\pgfplotsset{width=11cm, height=6cm, compat = 1.7}
\usetikzlibrary{patterns}
\makeatother

\mode<presentation>
{
  \usetheme{Marburg}
  % or ...

%  \setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}

\setbeamertemplate{footline}[frame number]


\date[Ver 0]{2013-04-01}


%\logo{\hfill\includegraphics[width=3cm]{cpt_logo.eps}}


%\pgfdeclareimage[height=0.05cm]{university-logo}{cpt-logo.jpg}
%\logo{\pgfuseimage{university-logo}}


% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
%\AtBeginSection[]
%{
%  \begin{frame}<beamer>{Outline}
%    \tableofcontents[currentsection,currentsubsection]
%  \end{frame}
%}


%\usebeamertemplate*{logo}
%\usepackage{graphicx}


\newcommand{\comment}[1]{%
}%

\begin{document}
\sisetup{%
  output-decimal-marker = {,}%
    ,output-exponent-marker = \ensuremath{\mathrm{E}}%
    ,input-complex-roots = {i}
    ,output-complex-root = \ensuremath{\mathbf{j}}%
  ,separate-uncertainty
    ,parse-numbers=false%
}


\begin{frame}{Four-quadrant metering}
\vfill
The total apparent power can end up in any of the four quadrants.  
\uncover<2->{Quadrant \Romanbar{1} (lagging)}
\uncover<3->{and \Romanbar{4} (leading) are the forward or export direction,}
\uncover<4->{with \Romanbar{2} and \Romanbar{3} the reverse or import direction.}

\tikzstyle{txt} = []% [rectangle, rounded corners, minimum width=0cm, minimum height=0cm,text centered, draw=white, fill=white]
\pause{\small
\begin{tikzpicture}
\begin{axis}[height=7cm, width=12cm
,enlargelimits=0.2
,axis lines = middle
,axis line style={draw=none}
%,axis line style={->}
,tick style={color=black}
,xtick = \empty
,xticklabels={}%
,yticklabels={}%
,ytick=\empty
,xlabel style={at=(current axis.right of origin), anchor=west,align=center}
%,xlabel = {$\Re$~(resistive load)}
,ylabel style={at=(current axis.above origin), anchor=south,align=center}
%,ylabel ={(inductive load)\\\si{+kvar}}
,ymin = -5.5, ymax=7,xmin=-8.5, xmax=12,axis equal image ]
\filldraw[white] (axis cs:0,0) circle (4);
\draw (axis cs:-4.5,0) -- (axis cs:-2,0);
\draw[->] (axis cs:2,0) -- (axis cs:5,0) node[anchor=west]{\si{+kW}~(resistive load)};
\draw (axis cs:0,-3) -- (axis cs:0,-4.5);
\draw [->](axis cs:0,3) -- (axis cs:0,5) node[anchor=south,align=center]{(inductive load)\\\si{+kvar}};

\only<5->{
\draw (axis cs:0,-2) -- (axis cs:0,2);
\draw (axis cs:0,0) circle (2);

\node(pp)at (axis cs:1,0)[txt, ]{\footnotesize 1.x.x};
\node(mp)at (axis cs:-1,0)[txt, ]{\footnotesize 2.x.x};
}
\only<6->{
\draw (axis cs:0,0) circle (3);

\node(pq)at (axis cs:0,2.47)[txt, ]{\footnotesize 3.x.x};
\node(pq)at (axis cs:0,-2.47)[txt, ]{\footnotesize 4.x.x};
}
\only<7->{

\draw (axis cs:0,0) circle (4);
\node(pq)at (axis cs:2.45,2.45)[txt,rotate=-45 ]{\footnotesize 5.x.x};
\node(pq)at (axis cs:-2.45,2.45)[txt,rotate=45 ]{\footnotesize 6.x.x};
\node(pq)at (axis cs:-2.45,-2.45)[txt,rotate=-45 ]{\footnotesize 7.x.x};
\node(pq)at (axis cs:2.45,-2.45)[txt,rotate=45 ]{\footnotesize 8.x.x};
}
%\draw[thick] (axis cs:0,0) circle (5);
%\addplot [-stealth, thick, ] coordinates {(3.5,3.5) (4.5,3.5)};
\only<2->{
\node(o) at  (axis cs:4.5,3){\Large$\cdot$};
\node(p) at  (axis cs:6,3)[anchor=west] {$+P$};
\node(q) at  (axis cs:4.5,4.5)[anchor=south] {$+Q$};
\draw[-stealth,very thick] (o) to (p) node {};
\draw[-stealth,very thick] (o) to (q) node {};
\node at  (axis cs:4.1,1.5)[anchor=west] {quadrant \Romanbar{1}};

}

\only<3->{

\node(o) at  (axis cs:4.5,-3){\Large$\cdot$};
\node(p) at  (axis cs:6,-3)[anchor=west] {$+P$};
\node(q) at  (axis cs:4.5,-4.5)[anchor=north] {$-Q$};
\draw[-stealth,very thick] (o) to (p) node {};
\draw[-stealth,very thick] (o) to (q) node {};
\node at  (axis cs:4.1,-1.5)[anchor=west] {quadrant \Romanbar{4}};

}
\only<4->{

\node(o) at  (axis cs:-4.5,3){\Large$\cdot$};
\node(p) at  (axis cs:-6,3)[anchor=east] {$-P$};
\node(q) at  (axis cs:-4.5,4.5)[anchor=south] {$+Q$};
\draw[-stealth,very thick] (o) to (p) node {};
\draw[-stealth,very thick] (o) to (q) node {};

\node(o) at  (axis cs:-4.5,-3){\Large$\cdot$};
\node(p) at  (axis cs:-6,-3)[anchor=east] {$-P$};
\node(q) at  (axis cs:-4.5,-4.5)[anchor=north] {$-Q$};
\draw[-stealth,very thick] (o) to (p) node {};
\draw[-stealth,very thick] (o) to (q) node {};
\node at  (axis cs:-4.1,1.5)[anchor=east] {quadrant \Romanbar{2}};
\node at  (axis cs:-4.1,-1.5)[anchor=east] {quadrant \Romanbar{3}};

}

\end{axis}
\end{tikzpicture}
}

\uncover<5->{There are also standard OBIS codes identifying the different energy registers, for example 1.x.x for \si{kWh} consumed.}

\end{frame}


\end{document}

答案1

一种可能性是使用线和弧完全绘制区域轮廓。此外,您可以使用\foreachscope命令来简化任务。在这种情况下,将所需的颜色预定义为颜色 1、颜色 2 等很方便。

tikz我让你的 MWE 变得更简约一些,并且我用来绘制图表pgfplots(没有axis)以减少代码。

这就是我所拥有的:

\documentclass[%handout,
  10pt]{beamer}

\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{romanbar}
\usepackage{siunitx}

\mode<presentation>{\usetheme{Marburg}}
\setbeamertemplate{footline}[frame number]
\tikzstyle{txt} = []

\definecolor{color1}{HTML}{FF6666}
\definecolor{color2}{HTML}{FFB266}
\definecolor{color3}{HTML}{FFFF66}
\definecolor{color4}{HTML}{B2FF66}
\definecolor{color5}{HTML}{66FF66}
\definecolor{color6}{HTML}{66FFB2}
\definecolor{color7}{HTML}{66FFFF}
\definecolor{color8}{HTML}{66B2FF}


\begin{document}
\begin{frame}{Four-quadrant metering}
\vfill
The total apparent power can end up in any of the four quadrants.
\uncover<2->{Quadrant \Romanbar{1} (lagging)}
\uncover<3->{and \Romanbar{4} (leading) are the forward or export direction,}
\uncover<4->{with \Romanbar{2} and \Romanbar{3} the reverse or import direction.}

\pause{\small
\begin{tikzpicture}[scale=0.4]
\useasboundingbox (-12.25,-5.7) rectangle (12.25,7.3); % This prevents the diagram moving around
\draw     (-4.5, 0) -- (-2,0);
\draw[->] ( 2  , 0) -- (5,0) node[right]{+\si{kW}~(resistive load)};
\draw     ( 0  ,-3) -- (0,-4.5);
\draw[->] ( 0  , 3) -- (0,5) node[above,align=center]{(inductive load)\\+\si{kvar}};

\only<2->{
\fill (4.5,3) circle (2.5pt) node (o) {};
\node(p) at  (6,3)    [right] {$+P$};
\node(q) at  (4.5,4.5)[above] {$+Q\phantom{+}$};
\node    at  (4.1,1.5)[right] {quadrant \Romanbar{1}};
\draw[-stealth,very thick] (o) to (p);
\draw[-stealth,very thick] (o) to (q);
}

\only<3->{
\fill (4.5,-3) circle (2.5pt) node (o) {};
\node(p) at (6,-3)    [right] {$+P$};
\node(q) at (4.5,-4.5)[below] {$-Q\phantom{+}$};
\node    at (4.1,-1.5)[right] {quadrant \Romanbar{4}};
\draw[-stealth,very thick] (o) to (p);
\draw[-stealth,very thick] (o) to (q);
}

\only<4->{
\fill (-4.5,3) circle (2.5pt) node (o) {};
\node(p) at (-6,3)    [left]  {$-P$};
\node(q) at (-4.5,4.5)[above] {$+Q\phantom{+}$};
\node    at (-4.1,1.5)[left]  {quadrant \Romanbar{2}};
\draw[-stealth,very thick] (o) to (p) node {};
\draw[-stealth,very thick] (o) to (q) node {};

\fill (-4.5,-3) circle (2.5pt) node (o) {};
\node(p) at (-6,-3)    [left]  {$-P$};
\node(q) at (-4.5,-4.5)[below] {$-Q\phantom{+}$};
\node    at (-4.1,-1.5)[left]  {quadrant \Romanbar{3}};
\draw[-stealth,very thick] (o) to (p) node {};
\draw[-stealth,very thick] (o) to (q) node {};
}

\only<5->{\foreach\i in {1,2}{
\begin{scope}[rotate=180*\i-270]
  \draw[fill=color\i] (2,0) arc (0:180:2) -- cycle;
  \node at (0,1) [txt] {\footnotesize\i.x.x};
\end{scope}
}}

\only<6->{\foreach\i in {3,4}{
\begin{scope}[rotate=180*\i-540]
  \draw[fill=color\i] (3,0) arc (0:180:3) --++ (1,0) arc (180:0:2) -- cycle;
  \node at (0,2.5) [txt] {\footnotesize\i.x.x};
\end{scope}
}}

\only<7->{
\foreach\i in {5,...,8}{
\pgfmathsetmacro\angle{Mod(\i,2)>0?-45:45}
\begin{scope}[rotate=90*\i-450]
  \draw[fill=color\i] (4,0) arc (0:90:4) --++ (0,-1) arc (90:0:3) -- cycle;
  \node at (45:3.5) [txt,rotate=\angle] {\footnotesize\i.x.x};
\end{scope}
}}
\end{tikzpicture}}

\uncover<5->{There are also standard OBIS codes identifying the different energy registers, for example 1.x.x for \si{kWh} consumed.}
\end{frame}
\end{document}

在此处输入图片描述

相关内容