Re: 帯グラフ

名前: トノ
日時: 2005-12-02 00:21:31
IPアドレス: 222.159.240.*

>>39602 この話題、なぜか余所に飛び火しているようで‥‥ emath のサポート・ページの掲示板を覗いてみると幸せになれるかもしれません。 さらに、某所で以下のような記述も見かけました。 ※ 残念ながら破線で結ぶところまでは入っていないようですが、「現実逃避に」といって こんなソースを書いてしまうあたり、やっぱりすごいと思う‥‥ \documentclass{jarticle} \usepackage{color,graphicx} \makeatletter \newcount\@BP@items \def\BandPlot{\@testopt\@BandPlot{}} \def\@BandPlot[#1]#2{% \leavevmode \hbox{% \BandPlotInit{#1}% \@BP@items\z@ \dimen@\z@ \count@\z@ \edef\@tempa{\zap@space#2 \@empty}% \def\@tempb{\@for\@tempa:=}% %%% データの桁数が増えると,このような計算では不都合があるが… %%% その場合には,適当なマクロで“浮動小数点型”の数値の計算を行えばいい. \expandafter\@tempb\@tempa\do{% \advance\count@\@ne \expandafter\edef\csname @BP@data@\the\count@\endcsname{\@tempa}% \advance\dimen@\@tempa\p@ \expandafter\edef\csname @BP@currpos@\the\count@\endcsname{\the\dimen@}% \advance\@BP@items\@ne}% \def\@tempx##1.##2##3##4\@nil{##1\ifnum##2##3>\z@ .##2##3\fi}% \count@\z@ \@whilenum\count@<\@BP@items\do{% \advance\count@\@ne \@tempdima\csname @BP@currpos@\the\count@\endcsname\relax \@tempdimb\dimen@ \@BPI@divide\@tempdima/\@tempdimb \edef\@tempa{\strip@pt\@tempdima}% \@tempdima\@BP@width\relax \@tempdima\@tempa\@tempdima \expandafter\edef\csname @BP@currpos@\the\count@\endcsname{% \the\@tempdima}% \@tempdima\csname @BP@data@\the\count@\endcsname\p@ \@tempdimb\dimen@ \multiply\@tempdima 10\relax \divide\@tempdimb 10\relax \@BPI@divide\@tempdima/\@tempdimb \advance\@tempdima.005\p@ \edef\@tempa{\expandafter\altrem@pt\the\@tempdima}% \edef\@tempa{\expandafter\@tempx\@tempa00\@nil}% \expandafter\let\csname @BP@percentage@\the\count@\endcsname\@tempa}% \def\Value{\@nameuse{@BP@data@\the\count@}}% \def\Percentage{\@nameuse{@BP@percentage@\the\count@}}% \count@\z@ \@tempdima\z@ \@whilenum\count@<\@BP@items\do\@BP@makeitem \vbox to\@BP@height{% \begingroup \@BP@setcolor\@BP@linecolor \hrule \@height\@BP@linewidth \vskip-\@BP@linewidth \hbox to\@BP@width{\hfil \vrule\@width\@BP@linewidth \@height\@BP@height}% \vskip-\@BP@linewidth \hrule \@height\@BP@linewidth \endgroup}}} \def\@BPI@divide#1/#2{% \@whiledim#1>32\p@\do{\divide#1\tw@ \divide#2\tw@}% \multiply#1\@cclvi \divide#2\@cclvi \divide#1#2\relax} \begingroup \catcode`P=12 \catcode`T=12 \lowercase{% \def\x{\def\altrem@pt##1PT{##1}}}% \expandafter\endgroup\x \def\@BP@setcolor#1{% \ifx#1\@empty\else \edef\@tempa{\noexpand\color[\@BP@colormodel]{#1}}% \@tempa \fi} \def\@BP@makeitem{% \advance\count@\@ne \@tempdimb\csname @BP@currpos@\the\count@\endcsname\relax \rlap{% \hskip\@tempdima \dimen@\@tempdimb \advance\dimen@-\@tempdima \@tempdima\@BP@height\relax \@ifundefined{@BP@pattern@\the\count@}% {\let\@tempa\@BP@default@pattern}% {\expandafter\let\expandafter\@tempa \csname @BP@pattern@\the\count@\endcsname}% \def\@tempx##1[##2]##3\@nil{\def\@tempa{##1}\def\@tempb{##2}}% \expandafter\@tempx\@tempa[]\@nil \@ifundefined{@BP@style@\@tempa}{\def\@tempa{fill}}\relax \rlap{\@nameuse{@BP@style@\@tempa}}% \begingroup \@BP@setcolor\@BP@linecolor \@tempdimb\@BP@linewidth\relax \ifnum\count@>\@ne \hskip-.5\@tempdimb \fi \vrule \@width\@tempdimb \@height\@tempdima \ifnum\count@>\@ne \hskip-.5\@tempdimb \else \hskip-\@tempdimb \fi \endgroup \vbox to\@tempdima{% \vss \hbox to\dimen@{% \hss \@ifundefined{@BP@label@\the\count@}% {\@BP@default@label}% {\@nameuse{@BP@label@\the\count@}}% \hss}% \vss}}% \@tempdima\@tempdimb} \def\@BP@style@none{} \def\@BP@style@hlines{% \ifx\@tempb\@empty \def\@tempb{\p@}\fi \@tempdimb\@tempb\relax \advance\@tempdimb-.4\p@ \@BP@style@hlines@} \def\@BP@style@hlines@{% \vbox to\@tempdima{% \cleaders \vbox{% \vskip.5\@tempdimb \hrule\@width\dimen@ \vskip.5\@tempdimb}% \vfil}} \def\@BP@style@vlines{% \ifx\@tempb\@empty \def\@tempb{\p@}\fi \@tempdimb\@tempb\relax \advance\@tempdimb-.4\p@ \@BP@style@vlines@} \def\@BP@style@vlines@{% \hbox to\dimen@{% \cleaders \hbox{% \hskip.5\@tempdimb \vrule\@height\@tempdima \hskip.5\@tempdimb}% \hfil}} \def\@BP@style@crosslines{% \ifx\@tempb\@empty \def\@tempb{\p@}\fi \@tempdimb\@tempb\relax \advance\@tempdimb-.4\p@ \@BP@style@hlines@ \kern-\dimen@ \@BP@style@vlines@} \def\@BP@style@fill{% \begingroup \edef\@tempb{\vrule\@width\the\dimen@ \@height\the\@tempdima}% \expandafter\@BP@setcolor\csname @BP@pattern@\the\count@\endcsname \@tempb \endgroup} \let\Percentage\relax \let\Value\relax \def\BandPlotInit#1{% \protected@edef\@tempa{#1}% \def\@tempb{\@for\@tempa:=}% \expandafter\@tempb\@tempa\do\@BandPlotInit} \def\@BandPlotInit{% \toks@\expandafter{\@tempa}% \protected@edef\@tempa{\expandafter\@firstofone\the\toks@\@empty}% \edef\@tempb{\noexpand\@nil\space\noexpand\@nil}% \expandafter\expandafter\expandafter\@cut@last@space \expandafter\@tempa\@tempb\@nnil \expandafter\@BPI@sprit@option\@tempa==\@nil \@onelevel@sanitize\@BPI@optname \@BPI@parse@optname\@BPI@optname \@ifundefined{@BPI@opt@\@BPI@optname}% {\GenericError{}% {Unknown option `\@BPI@optname' for \string\BandPlotInit\space or \string\BandPlot}% {Examine available options for \string\BandPlotInit\space or \string\BandPlot.}% \@ehc} {\@nameuse{@BPI@opt@\@BPI@optname}}} \def\@cut@last@space#1 \@nil#2\@nnil{% \def\@tempa{#2}% \ifx\@tempa\@empty \@cut@last@space@#1\@nil\@nnil \else \def\@tempa{#1}% \fi} \def\@cut@last@space@#1\@nil#2\@nnil{\def\@tempa{#1}} \def\@BPI@sprit@option#1=#2=#3\@nil{% \def\@BPI@optname{#1}% \def\@BPI@optarg{#2}} \def\@BPI@parse@optname#1{% \let\@tempa\@empty \let\@tempb\@empty \expandafter\@BPI@parse@optname@#1\@nil \let\@BPI@optname\@tempa \let\@BPI@optnum\@tempb} \def\@BPI@parse@optname@#1{% \def\@tempc{#1}% \ifx\@tempc\@nnil\else \edef\@tempc{\count@=`\@tempc\relax}\@tempc \@tempswafalse \ifnum`0>\count@ \else \ifnum`9<\count@ \else \@tempswatrue \fi\fi \if@tempswa \edef\@tempb{\@tempb#1}% \else \edef\@tempa{\@tempa\@tempb#1}% \let\@tempb\@empty \fi \expandafter\@BPI@parse@optname@ \fi} \def\@BPI@get@opt@opt#1[#2]#3\@nil{% \def\@BPI@optname{#1}% \def\@BPI@optopt{#2}} \def\@BPI@opt@width{\let\@BP@width\@BPI@optarg} \def\@BPI@opt@height{\let\@BP@height\@BPI@optarg} \def\@BPI@opt@colormodel{\let\@BP@colormodel\@BPI@optarg} \def\@BPI@opt@linecolor{\let\@BP@linecolor\@BPI@optarg} \def\@BPI@opt@linewidth{\let\@BP@linewidth\@BPI@optarg} \def\@BPI@opt@label{\@BPI@set@option{label}} \def\@BPI@opt@pattern{\@BPI@set@option{pattern}} \def\@BPI@set@option#1{% \count@=0\@BPI@optnum\relax \ifnum\count@=\z@ \expandafter\let\csname @BP@default@#1\endcsname\@BPI@optarg \else \expandafter\let\csname @BP@#1@\the\count@\endcsname\@BPI@optarg \fi} \BandPlotInit{% width=50mm,% 帯グラフの幅 height=10mm,% 帯グラフの高さ colormodel=gray,% 帯グラフの各項目に色付けを行う場合のカラーモデル linecolor=,% 帯グラフの周囲および各項目の境界に引かれる線の色 % (空文字列なら,色の設定をせずに描画,) % linecolor=.7,% これは,colormodel=gray の設定の下で線の色を % 30% のグレーにする設定. % ほかにも colormode=rgb の設定の下で % linecolor={0,0,1}(青色)のようにカラーモデルに応じた % パラメータ指定が可能 linewidth=.4pt,% 帯グラフの周囲および各項目の境界に引かれる線の太さ label=,% 帯グラフの各項目に書き込まれる文字列の指定 % label1=(1),% これは 1 番目の項目に``(1)''という文字列を書き込む指定 % 同様に label<N>=... という形式で <N> 番目の項目に書き込む % 文字列を指定可能 % 番号を与えずに単に label=... とした場合には, % 番号つきの label オプションで設定した文字列がない場合に % 用いるデフォルトの文字列を設定 % label=\Percentage, % これは \BandPlot の引数から決まる各項目の % パーセンテージを書き込む場合の設定 % label=\Value, % これは \BandPlot の引数で与えた各項目の値を % 書き込む場合の設定 % label={\protect\tiny\protect\shortstack{\Value\protect\\ \Percentage}} % のような設定も可能 pattern=none,% 各項目の塗り方の設定 % none: 何もしない % hlines[***]: 線の間隔が *** の横線で埋め尽くす % vlines[***]: 線の間隔が *** の縦線で埋め尽くす % crosslines[***]: 線の間隔が *** の格子で埋め尽くす % pattern=0 のように linecolor と同様のカラーモデルに対応する % パラメータを記述することも可能 pattern1=hlines[3pt],% label の場合と同様に,<N> 番目の項目に対する指定を pattern2=vlines[3pt],% pattern<N>=... として与えることが可能 pattern3=crosslines[3pt],% 上記の pattern=none というのは 7 番目以降の項目に pattern4=hlines[1.5pt],% 対するデフォルトの設定 pattern5=vlines[1.5pt], pattern6=crosslines[1.5pt]} \makeatother \begin{document} \noindent\BandPlot{30,20,10}\\ 凡例: \begingroup\BandPlotInit{width=10mm,height=5mm}% \raisebox{-1.5mm}{\BandPlot[{pattern1=hlines[3pt]}]{1}}:男性, \raisebox{-1.5mm}{\BandPlot[{pattern1=vlines[3pt]}]{1}}:女性, \raisebox{-1.5mm}{\BandPlot[{pattern1=crosslines[3pt]}]{1}}:その他 \endgroup \vspace{3\baselineskip} \noindent \BandPlot[label=\textsf{\Percentage\%}, label3=\protect\textcolor{white}{\protect\scalebox{.6}[1]{\textsf{\Percentage\%}}}, pattern1=.9,pattern2=.75,pattern3=.6]{30,20,10} \end{document}

この書き込みへの返事:

お名前
題名 
メッセージ(タグは <a href="...">...</a> だけ使えます)