Re: 帯グラフ

名前: トノ
日時: 2005-12-03 08:35:23
IPアドレス: 222.159.240.*

>>39607 何と改良版が出たようです。いやはや生産的な現実逃避だこと。 ※ 元質問者の深見さんはもう見ておられないかしらん。 \documentclass{jarticle} \usepackage{color,graphicx} \makeatletter \newif\if@BP@local \@BP@localfalse \newcount\@BP@items \def\BandPlot{\@testopt\@BandPlot{}} \def\@BandPlot[#1]#2{% \@BandPlot@beforebox \hbox{% \@BP@localtrue \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@ \def\@BP@templist{\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}% \edef\@BP@templist{\@BP@templist\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}% \@BP@putcaption \def\Value{\@nameuse{@BP@data@\the\count@}}% \def\Percentage{\@nameuse{@BP@percentage@\the\count@}}% \count@\z@ \@tempdima\z@ \let\@BP@lastitem\relax \if@inBPS \ifx\@BP@prev@positions\@empty\else \def\@BP@lastitem{\@BP@show@correspondence@\z@}% \fi\fi \@whilenum\count@<\@BP@items\do\@BP@makeitem \global\let\@BP@prev@positions\@BP@templist \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}% \@BP@putcaption@last \@BP@lastitem}} \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 \edef\NUMBER{\the\count@}% \@tempdimb\csname @BP@currpos@\the\count@\endcsname\relax \rlap{% \hskip\@tempdima \@BP@show@correspondence \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@show@correspondence{% \if@inBPS \begingroup \ifx\@BP@prev@positions\@empty\else \def\@tempz##1,##2\@nil{% \@tempdimb##1\relax \gdef\@BP@prev@positions{##2}}% \expandafter\@tempz\@BP@prev@positions\@nil \advance\@tempdimb-\@tempdima \@BP@show@correspondence@\@tempdimb \fi \endgroup \fi} \def\@BP@show@correspondence@#1{% \dimen@#1\relax \dimen@ii\@BP@bandsep\relax \begingroup \@tempdima\dimen@ \ifdim\@tempdima<\z@ \@tempdima-\@tempdima \fi \@tempdimb\dimen@ii \ifdim\@tempdima<\@tempdimb \dimen@\@tempdimb \@BPI@divide\@tempdima/\@tempdimb \edef\@tempa{\strip@pt\@tempdima}% \else \dimen@\@tempdima \@BPI@divide\@tempdimb/\@tempdima \edef\@tempa{\strip@pt\@tempdimb}% \fi \@tempdima\@tempa\p@ \@tempdima\@tempa\@tempdima \advance\@tempdima\p@ \@tempdimb 400\@tempdima \@whiledim\@tempdimb>441\p@\do{% \divide\@tempdimb 441\relax \@tempdima\@tempdimb \@tempdimb 400\@tempdima \multiply\dimen@ 21\relax \divide\dimen@ 20\relax}% \advance\@tempdima-\p@ \edef\@tempa{\strip@pt\@tempdima}% \@tempdima-\@tempa\p@ \divide\@tempdima 4\relax \advance\@tempdima\p@ \@tempdima\@tempa\@tempdima \divide\@tempdima\tw@ \advance\@tempdima\p@ \edef\@tempa{\strip@pt\@tempdima}% \dimen@\@tempa\dimen@ \dimen@ii\@BP@dotsep\relax \divide\dimen@\dimen@ii \count@\dimen@ \advance\count@\@ne \edef\@tempa{\count@=\the\count@\relax}% \expandafter\endgroup\@tempa \divide\dimen@\count@ \divide\dimen@ii\count@ \advance\count@\@ne \edef\@tempa{% \noexpand\multiput (0,0)(\strip@pt\dimen@,\strip@pt\dimen@ii)% {\the\count@}}% \smash{\raise\@BP@height\hbox to\z@{% \unitlength\p@ \@tempa{\circle*{1}}% \hss}}} \def\@BP@dotsep{3pt} \def\@BP@putcaption{% \let\@BP@putcaption@last\relax \if@inBPS \begingroup \def\@tempa{\z@}% \def\@tempb{\z@}% \let\@tempc\relax \let\@tempd\relax \ifx\@BP@caption\@empty\else \if L\@BP@captionpos\relax \def\@tempa{\@BP@captionsep}% \def\@tempd{\let\@BP@caption\@empty}% \else \def\@tempb{\@BP@captionsep}% \def\@tempc{\let\@BP@caption\@empty}% \fi \fi \global\setbox\@BPS@Lcaptions\vbox{% \unvbox\@BPS@Lcaptions \hbox{\@tempc \@BP@putcaption@ \hskip\@tempa}}% \global\setbox\@BPS@Rcaptions\vbox{% \unvbox\@BPS@Rcaptions \hbox{\@tempd \hskip\@tempb \@BP@putcaption@}}% \endgroup \else \ifx\@BP@caption\@empty\else \if L\@BP@captionpos\relax \hbox{\@BP@putcaption@ \hskip\@BP@captionsep}% \else \def\@BP@putcaption@last{% \hbox{\hskip\@BP@captionsep \@BP@putcaption@}}% \fi \fi \fi} \def\@BP@putcaption@{\vbox to\@BP@height{\vss\hbox{\@BP@caption}\vss}} \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 \let\NUMBER\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}% {\ifx\@BPI@optname\@empty\else \GenericError{}% {Unknown option `\@BPI@optname' for \string\BandPlotInit\space or \string\BandPlot}% {Examine available options for \string\BandPlotInit\space or \string\BandPlot.}% \@ehc \fi}% {\@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@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@bandsep{\let\@BP@bandsep\@BPI@optarg} \def\@BPI@opt@caption{\if@BP@local \let\@BP@caption\@BPI@optarg \fi} \def\@BPI@opt@captionsep{\let\@BP@captionsep\@BPI@optarg} \def\@BPI@opt@captionpos{% \@onelevel@sanitize\@BPI@optarg \edef\@tempa{\expandafter\@car\@BPI@optarg!\@nil}% \if l\@tempa \def\@BP@captionpos{L}\fi \if L\@tempa \def\@BP@captionpos{L}\fi \if r\@tempa \def\@BP@captionpos{R}\fi \if R\@tempa \def\@BP@captionpos{R}\fi} \let\@BP@caption\@empty \def\@BPI@opt@label{\@BPI@set@option{label}} \def\@BPI@opt@pattern{% \if@BP@local \let\@tempa\@BPI@optarg \@onelevel@sanitize\@tempa \@BPI@opt@pattern@check@specialarg\@tempa \ifx\@tempb\@empty\else \afterassignment\remove@to@nnil \count@=0\@tempb\relax\@nnil \ifnum\count@=\z@ \let\@BPI@optarg\@BP@global@default@pattern \else \expandafter\let\expandafter\@BPI@optarg \csname @BP@global@pattern@\the\count@\endcsname \fi \fi \fi \@BPI@set@option{pattern}% \if@BP@local\else \ifnum\count@=\z@ \let\@BP@global@default@pattern\@BPI@optarg \else \expandafter\let \csname @BP@global@pattern@\the\count@\endcsname \@BPI@optarg \fi \fi} \begingroup \catcode`D=12 \catcode`E=12 \catcode`F=12 \catcode`A=12 \catcode`U=12 \catcode`L=12 \catcode`T=12 \lowercase{% \def\x{% \def\@BPI@opt@pattern@check@specialarg##1{% \expandafter\@BPI@opt@pattern@check@specialarg@##1DEFAULTDEFAULT\@nil} \def\@BPI@opt@pattern@check@specialarg@##1DEFAULT##2DEFAULT##3\@nil{% \def\@tempa{##1}% \def\@tempb{##2}}}} \expandafter\endgroup\x \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} \newif\if@inBPS \@inBPSfalse \newbox\@BPS@Lcaptions \newbox\@BPS@Rcaptions \newbox\@BPS@body \def\BandPlotSequence{\@testopt\@BandPlotSequence{}} \def\@BandPlotSequence[#1]#2{% \ifvmode \leavevmode \fi \global\setbox\@BPS@Lcaptions\box\voidb@x \global\setbox\@BPS@Rcaptions\box\voidb@x \setbox\@BPS@body\vbox{% \@inBPStrue \BandPlotInit{#1}% \def\@BandPlot@beforebox{% \ifvoid\@BPS@Lcaptions\else \nointerlineskip\vskip\@BP@bandsep\relax \global\setbox\@BPS@Lcaptions\vbox{% \unvbox\@BPS@Lcaptions \vskip\@BP@bandsep}% \global\setbox\@BPS@Rcaptions\vbox{% \unvbox\@BPS@Rcaptions \vskip\@BP@bandsep}% \fi}% \global\let\@BP@prev@positions\@empty #2}% \hbox{% \@BPS@recounstruct@Lcaptions \box\@BPS@Lcaptions \box\@BPS@body \box\@BPS@Rcaptions}} \def\@BPS@recounstruct@Lcaptions{% \setbox\tw@\box\@BPS@Lcaptions \setbox\z@\vbox{% \dimen@\z@ \unvcopy\tw@ \@BPS@recounstruct@LcaptionsA \global\setbox\@BPS@Lcaptions\box\voidb@x \unvbox\tw@ \@BPS@recounstruct@LcaptionsB}} \def\@BPS@recounstruct@LcaptionsA{% \setbox\z@\lastbox \ifvoid\z@\else \unskip \ifdim\dimen@<\wd\z@ \dimen@\wd\z@ \fi \expandafter\@BPS@recounstruct@LcaptionsA \fi} \def\@BPS@recounstruct@LcaptionsB{% \setbox\z@\lastbox \ifvoid\z@\else \@tempdima=\lastskip \unskip \global\setbox\@BPS@Lcaptions\vbox{% \vskip\@tempdima \hbox to\dimen@{\hfill\box\z@}% \unvbox\@BPS@Lcaptions} \expandafter\@BPS@recounstruct@LcaptionsB \fi} \let\@BandPlot@beforebox\leavevmode % %%% デフォルト設定 %%% もちろん,変更可.ただし,この設定例兼説明で設定している項目のうち %%% 番号なしのもの(つまり,pattern1〜pattern6 以外のもの)ついては, %%% 適切な値をデフォルト値として用意する必要がある. \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=(\NUMBER), % これは n 番目の項目に (n) と書き込む設定 % 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], bandsep=5mm,% \BandPlotSequence における,個々の帯グラフの間隔 captionsep=3mm,% \BandPlot の caption オプションで与えたキャプション文字列と % 帯グラフとの間隔 captionpos=L}% キャプション文字列の位置(帯グラフに対して,R: 右側,L: 左側) \makeatother \begin{document} \noindent\BandPlot[caption=何かの割合]{30,20,10}\\ 凡例: \begingroup \BandPlotInit{width=10mm,height=5mm}% \raisebox{-1.5mm}{\BandPlot[pattern1=default1]{1}}:男性, \raisebox{-1.5mm}{\BandPlot[pattern1=default2]{1}}:女性, \raisebox{-1.5mm}{\BandPlot[pattern1=default3]{1}}:その他 %%% \BandPlot のオプション引数において,pattern<N>=default<M> のように %%% 指定すると,<N> 番目の項目の塗りつぶしパターンを %%% “デフォルト設定における <M> 番目の項目の塗りつぶしパターン”に設定. %%% (上記の“凡例”を見たほうが,意味がわかりやすいかもしれない…) \endgroup \bigskip \noindent \BandPlot[label=\textsf{\Percentage\%}, label3=\protect\textcolor{white}{\protect\scalebox{.6}[1]{\textsf{\Percentage\%}}}, linewidth=0pt, pattern1=.9,pattern2=.75,pattern3=.6]{30,20,10} \begin{center}\fboxsep=1pt \BandPlotSequence [width=100mm, label=\protect\colorbox{white}{\protect\scriptsize(\NUMBER)}] { \BandPlot[caption=500年]{50,40,30,20,10} \BandPlot[caption=1000年]{40,30,30,30,20} \BandPlot[caption=1500年]{30,30,30,30,30} \BandPlot[caption=2000年]{20,30,30,30,40} \BandPlot[caption=2005年]{10,20,30,40,50} } \end{center} \end{document}

この書き込みへの返事:

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