我正在绘制一个基于绘制一些矩形的图形,其面积代表此类元素的相对数量,我遇到了两种意外情况:
(1) 我决定用矩形来绘制图形(如下所示)。完成绘图后,我愿意应用样式以获得圆边并将其设置为白色。然后我惊讶地发现它不能将样式应用于矩形。
(2) 我构建图例的方式不起作用,因为当使用定位创建节点时,绘图光标不会从原点移动。
\documentclass[11pt]{article}
\usepackage{color}
\usepackage{pgfplotstable,booktabs,array,colortbl,siunitx}
\usetikzlibrary{calc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\thispagestyle{empty} %Please, no page numbers or similar
\begin{tikzpicture}[scale=.3,yscale=-1]
% Defining stuff
\def\sep{0}
\definecolor{auxColori}{RGB}{124,121,247}
\definecolor{FAcolor}{RGB}{222,209,111}
\definecolor{Hcolor}{RGB}{146,209,105}
\definecolor{Gcolor}{RGB}{113,130,227}
\definecolor{CDIcolor}{RGB}{242,162,121}
\definecolor{CLIcolor}{RGB}{93,186,172}
\definecolor{CIDcolor}{RGB}{204,102,201}
\definecolor{Othercolor}{RGB}{191,96,124}
\definecolor{auxColor}{RGB}{120,190,240}
\definecolor{Qcolor}{RGB}{255,128,128}
% Drawing the rectangles
\draw [fill=Othercolor] (0,0) ++(-2.5,0) rectangle +(4.5,4);%18 other
\pgfmathsetmacro{\CIDheight}{7/2}
\pgfmathsetmacro{\CLIheight}{12/2}
\pgfmathsetmacro{\CDIheigth}{2*\sep+4+\CIDheight+\CLIheight}
\pgfmathsetmacro{\CDIwidth}{67/\CDIheigth}
\draw [fill=CIDcolor] (0,{\sep+4}) rectangle +(2,\CIDheight);% 7 CID
\draw [fill=CLIcolor] (0,{2*\sep+4+\CIDheight}) rectangle +(2,\CLIheight);%12 CLI
\draw [fill=CDIcolor] ({2+\sep},0) rectangle +(\CDIwidth,\CDIheigth);%67 CDI
\pgfmathsetmacro{\Gheight}{8/2.5}
\pgfmathsetmacro{\Hheight}{6/2.5}
\pgfmathsetmacro{\FAheight}{2*\sep+4+\Gheight+\Hheight}
\pgfmathsetmacro{\FAwidth}{69/\FAheight}
\pgfmathsetmacro{\Qwidth}{\sep+2.5+\FAwidth}
\pgfmathsetmacro{\Qheight}{90/\Qwidth}
\draw [fill=Gcolor] (0,{\sep+4}) rectangle +(-2.5 ,\Gheight);% 8 G
\draw [fill=Hcolor] (0,{2*\sep+4+\Gheight}) rectangle +(-2.5,\Hheight);%6 H
\draw [fill=FAcolor] ({-2.5+\sep},0) rectangle +(-\FAwidth,\FAheight);%69 FA
\draw [fill=Qcolor] (0,{\FAheight+\sep}) rectangle +(-\Qwidth,\Qheight);%90 Q
% Creating the legend
\tikzset{nameSt/.style={anchor=west}}
\draw[draw=Qcolor, fill=Qcolor] (10,0) node[nameSt] (Qname) {Q} ++(-.5,-.5) rectangle +(.5,.5);
\draw[draw=FAcolor, fill=FAcolor] node[nameSt, below=of Qname] (FAname) {FA} ++(-.5,-.5) rectangle +(.5,.5);
\draw[draw=Gcolor, fill=Gcolor] node[nameSt, below=of FAname] (Gname) {G} ++(-.5,-.5) rectangle +(.5,.5);
\end{tikzpicture}
\end{document}
有什么提示吗?
答案1
这是使用样式的圆角矩形的解决方案
\tikzset{
wrcorners/.style = {rounded corners=6pt,line width=1.8pt,draw=white}
}
以及图例的节点
\tikzset{nameSt/.style=
{anchor=west,rectangle,
minimum width=10pt,minimum height=10pt,
}}
\draw[] (8,1) node[nameSt,draw=Qcolor, fill=Qcolor,label=right:Q] (Qname) {};
\draw[] node[nameSt, draw=FAcolor, fill=FAcolor,below=of Qname,label=right:FA] (FAname) {} ;
\draw[] node[nameSt,draw=Gcolor, fill=Gcolor, below=of FAname,label=right:G] (Gname) {};
结果是
以下是完整代码
\documentclass[11pt]{article}
\usepackage{color}
\usepackage{pgfplotstable,booktabs,array,colortbl,siunitx}
\usetikzlibrary{calc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\tikzset{
wrcorners/.style = {rounded corners=6pt,line width=1.8pt,draw=white}
}
\begin{document}
\thispagestyle{empty} %Please, no page numbers or similar
\begin{tikzpicture}[scale=.3,yscale=-1]
% Defining stuff
\def\sep{0}
\definecolor{auxColori}{RGB}{124,121,247}
\definecolor{FAcolor}{RGB}{222,209,111}
\definecolor{Hcolor}{RGB}{146,209,105}
\definecolor{Gcolor}{RGB}{113,130,227}
\definecolor{CDIcolor}{RGB}{242,162,121}
\definecolor{CLIcolor}{RGB}{93,186,172}
\definecolor{CIDcolor}{RGB}{204,102,201}
\definecolor{Othercolor}{RGB}{191,96,124}
\definecolor{auxColor}{RGB}{120,190,240}
\definecolor{Qcolor}{RGB}{255,128,128}
% Drawing the rectangles
\draw [fill=Othercolor,wrcorners] (0,0) ++(-2.5,0) rectangle +(4.5,4);%18 other
\pgfmathsetmacro{\CIDheight}{7/2}
\pgfmathsetmacro{\CLIheight}{12/2}
\pgfmathsetmacro{\CDIheigth}{2*\sep+4+\CIDheight+\CLIheight}
\pgfmathsetmacro{\CDIwidth}{67/\CDIheigth}
\draw [fill=CIDcolor,wrcorners] (0,{\sep+4}) rectangle +(2,\CIDheight);% 7 CID
\draw [fill=CLIcolor,wrcorners] (0,{2*\sep+4+\CIDheight}) rectangle +(2,\CLIheight);%12 CLI
\draw [fill=CDIcolor,wrcorners] ({2+\sep},0) rectangle +(\CDIwidth,\CDIheigth);%67 CDI
\pgfmathsetmacro{\Gheight}{8/2.5}
\pgfmathsetmacro{\Hheight}{6/2.5}
\pgfmathsetmacro{\FAheight}{2*\sep+4+\Gheight+\Hheight}
\pgfmathsetmacro{\FAwidth}{69/\FAheight}
\pgfmathsetmacro{\Qwidth}{\sep+2.5+\FAwidth}
\pgfmathsetmacro{\Qheight}{90/\Qwidth}
\draw [fill=Gcolor,wrcorners] (0,{\sep+4}) rectangle +(-2.5 ,\Gheight);% 8 G
\draw [fill=Hcolor,wrcorners] (0,{2*\sep+4+\Gheight}) rectangle +(-2.5,\Hheight);%6 H
\draw [fill=FAcolor,wrcorners] ({-2.5+\sep},0) rectangle +(-\FAwidth,\FAheight);%69 FA
\draw [fill=Qcolor,wrcorners] (0,{\FAheight+\sep}) rectangle +(-\Qwidth,\Qheight);%90 Q
% Creating the legend
%\tikzset{nameSt/.style={anchor=west}}
%\draw[draw=Qcolor, fill=Qcolor] (10,0) node[nameSt] (Qname) {Q} ++(-.5,-.5) rectangle +(.5,.5);
%\draw[draw=FAcolor, fill=FAcolor] node[nameSt, below=of Qname] (FAname) {FA} ++(-.5,-.5) rectangle +(.5,.5);
%\draw[draw=Gcolor, fill=Gcolor] node[nameSt, below=of FAname] (Gname) {G} ++(-.5,-.5) rectangle +(.5,.5);
% Creating the legend
\tikzset{nameSt/.style=
{anchor=west,rectangle,
minimum width=10pt,minimum height=10pt,
}}
\draw[] (8,1) node[nameSt,draw=Qcolor, fill=Qcolor,label=right:Q] (Qname) {};
\draw[] node[nameSt, draw=FAcolor, fill=FAcolor,below=of Qname,label=right:FA] (FAname) {} ;
\draw[] node[nameSt,draw=Gcolor, fill=Gcolor, below=of FAname,label=right:G] (Gname) {};
\end{tikzpicture}
\end{document}