如何将不同绘图的相同绘图样式组合到列表中,并且每个绘图使用一种样式?

如何将不同绘图的相同绘图样式组合到列表中,并且每个绘图使用一种样式?

请参阅我的 MWE 的第 62 至 97 行 ( root locus 1 = {)。我必须为每个图定义相同的图样式。能否将这些行组合成类似于我的 MWE 的第 54 至 61 行 ( )?我搜索了类似或 的visualize as line/.list = {内容。style = {->, red}./list = {list of plots}every style = {->, red}

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
%pattern visualize as circle
\pgfooclass{circle visualizer}{
                               \attribute name;
                               \method circle visualizer(#1) {\pgfooset{name}{#1}}
                               \method default connects() {
                                                           \pgfoothis.get handle(\me)
                                                           \pgfkeysvalueof{/pgf/data visualization/obj}.connect(\me,visualize,visualize datapoint signal)
                                                          }
                               \method visualize() {
                                                    \pgfdvfilterpassedtrue
                                                    \pgfdvnamedvisualizerfilter
                                                    \ifpgfdvfilterpassed
                                                    \dovisualization
                                                    \fi
                                                   }
                               }
\def\dovisualization{
                     \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at begin}
                     \pgfpathcircle{\pgfpointdvdatapoint}{\pgfkeysvalueof{/data point/radius}}
                     \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at end}
                     }
\tikzdatavisualizationset{
                          visualize as circle/.style={
                                                      new object={
                                                                  when=after survey,
                                                                  store=/tikz/data visualization/visualizers/#1,
                                                                  class=circle visualizer,
                                                                  arg1=#1
                                                                 },
                                                      new visualizer={#1}{color=visualizer color,
                                                                          every path/.style={draw},}{},
                                                      /data point/set=#1},
                          visualize as circle/.default=circle
                         }

\begin{document}

  \begin{tikzpicture}
    \datavisualization[
                       school book axes,
                       all axes = {grid = none},
                       x axis = {label = $\Re$},
                       y axis = {
                                 unit length = 2em,
                                 label = $\Im$
                                },
                       clean ticks,
                       visualize as scatter = poles,
                       visualize as circle = zeros,
                       visualize as line/.list = {
                                                  root locus 1,
                                                  root locus 2,
                                                  root locus 3,
                                                  root locus 4,
                                                  root locus 5,
                                                  root locus 6
                                                 },
                       root locus 1 = {
                                       style = {
                                                ->,
                                                red
                                               }
                                      },
                       root locus 2 = {
                                       style = {
                                                ->,
                                                red
                                               }
                                      },
                       root locus 3 = {
                                       style = {
                                                ->,
                                                red
                                               }
                                      },
                       root locus 4 = {
                                       style = {
                                                ->,
                                                red
                                               }
                                      },
                       root locus 5 = {
                                       style = {
                                                ->,
                                                red
                                               }
                                      },
                       root locus 6 = {
                                       style = {
                                                ->,
                                                red
                                               }
                                      }
                      ]
    data[set = poles] {
                       x,     y
                       -5,     0
                       -3,     0
                       -3,    -1
                       -3,     1
                        0,     0
                         .05,  0
                      }
    data[set = zeros] {
                       x,     y, radius
                       -5.2,  0, 2pt
                       -3.2,  0, 2pt
                       -1,    0, 2pt
                       -1.05, 0, 2pt
                      }
    data[set = asymptotes] {
                            x,    y
                            -1.8, -5.5
                            -1.8,  5.5
                           }
    data[set=root locus 1] {
                            x,      y
                             0,     0
                             0,      .01
                             0,      .015
                             0,      .024
                             -.001,  .037
                             -.002,  .057
                             -.005,  .089
                             -.013,  .137
                             -.031,  .211
                             -.075,  .32
                             -.129,  .408
                             -.183,  .473
                             -.247,  .53
                             -.31,   .572
                             -.372,  .6
                             -.431,  .618
                             -.496,  .628
                             -.554,  .628
                             -.605,  .621
                             -.648,  .609
                             -.716,  .579
                             -.764,  .548
                             -.835,  .482
                             -.874,  .433
                             -.915,  .366
                             -.967,  .236
                             -.987,  .152
                             -.994,  .098
                             -.998,  .063
                             -.999,  .041
                            -1,      .026
                            -1,      .017
                            -1,      .011
                            -1,      .007
                            -1,      .005
                            -1,      .003
                            -1,      .002
                            -1,      .001
                            -1,     0
                           }
    data[set=root locus 2] {
                            x,      y
                             0,     0
                             0,     -.01
                             0,     -.015                                 
                             0,     -.024
                             -.001, -.037
                             -.002, -.057
                             -.005, -.089
                             -.013, -.137
                             -.031, -.211
                             -.075, -.32
                             -.129, -.408
                             -.183, -.473
                             -.247, -.53
                             -.31,  -.572
                             -.372, -.6
                             -.431, -.618
                             -.496, -.628
                             -.554, -.628
                             -.605, -.621
                             -.648, -.609
                             -.716, -.579
                             -.764, -.548
                             -.835, -.482
                             -.874, -.433
                             -.915, -.366
                             -.967, -.236
                             -.987, -.152
                             -.994, -.098
                             -.998, -.063
                             -.999, -.041
                            -1,     -.026
                            -1,     -.017
                            -1,     -.011
                            -1,     -.007
                            -1,     -.005
                            -1,     -.003
                            -1,     -.002
                            -1,     -.001
                            -1,     0}
    data[set=root locus 3] {
                            x,    y
                            -5,   0
                            -5.2, 0
                           }
    data[set=root locus 4] {
                            x,      y
                            -3,     1
                            -3,     1.001
                            -2.999, 1.001
                            -2.998, 1.003
                            -2.996, 1.007
                            -2.990, 1.017
                            -2.977, 1.04
                            -2.947, 1.095
                            -2.882, 1.22
                            -2.81,  1.36
                            -2.742, 1.493
                            -2.665, 1.645
                            -2.592, 1.793
                            -2.522, 1.939
                            -2.457, 2.083
                            -2.385, 2.256
                            -2.321, 2.427
                            -2.266, 2.595
                            -2.218, 2.76
                            -2.143, 3.076
                            -2.089, 3.373
                            -2.009, 4.009
                            -1.963, 4.563
                            -1.913, 5.509
                           }
    data[set=root locus 5] {
                            x,      y
                            -3,     -1
                            -3,     -1.001
                            -2.999, -1.001
                            -2.998, -1.003
                            -2.996, -1.007
                            -2.99,  -1.017
                            -2.977, -1.04
                            -2.947, -1.095
                            -2.882, -1.22
                            -2.81,  -1.36
                            -2.742, -1.493
                            -2.665, -1.645
                            -2.592, -1.793
                            -2.522, -1.939
                            -2.457, -2.083
                            -2.385, -2.256
                            -2.321, -2.427
                            -2.266, -2.595
                            -2.218, -2.76
                            -2.143, -3.076
                            -2.089, -3.373
                            -2.009, -4.009
                            -1.963, -4.563
                            -1.913, -5.509
                           }
    data[set=root locus 6] {
                            x,    y
                            -3,   0
                            -3.2, 0
                           };
  \end{tikzpicture}

\end{document}

暗示:如果我使用every visualizer/.style = {->,red}比圆圈(在x轴上)也是红色的,它们应该保持黑色。

提前感谢您的帮助和努力!

答案1

改编

  • 我添加了一个样式set style for plots={<style>}{<list of plots>},它在内部使用set plots stylemy plot style设置所有给定图的样式。
    set style for plots/.style 2 args={
        my plot style/.style={#1},
        set plots style/.list={#2},
    },
    set plots style/.style={#1 = {style={data visualization/my plot style}}}, %internal
  • 使用示例:set style for plots={->,red}{root locus 1, root locus 2}
  • (我可以在缩进中看到模式,但是可读性不是很好,所以我将其更改为默认。)

代码

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
%pattern visualize as circle
\pgfooclass{circle visualizer}{
    \attribute name;
    \method circle visualizer(#1) {\pgfooset{name}{#1}}
    \method default connects() {
        \pgfoothis.get handle(\me)
        \pgfkeysvalueof{/pgf/data visualization/obj}.connect(\me,visualize,visualize datapoint signal)
    }
    \method visualize() {
        \pgfdvfilterpassedtrue
        \pgfdvnamedvisualizerfilter
        \ifpgfdvfilterpassed
            \dovisualization
        \fi
    }
}
\def\dovisualization{
    \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at begin}
    \pgfpathcircle{\pgfpointdvdatapoint}{\pgfkeysvalueof{/data point/radius}}
    \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at end}
}
\tikzdatavisualizationset{
    visualize as circle/.style={
        new object={
            when=after survey,
            store=/tikz/data visualization/visualizers/#1,
            class=circle visualizer,
            arg1=#1
        },
        new visualizer={#1}{color=visualizer color,every path/.style={draw},}{},
        /data point/set=#1
    },
    visualize as circle/.default=circle,
    % new:
    set style for plots/.style 2 args={
        my plot style/.style={#1},
        set plots style/.list={#2},
    },
    set plots style/.style={#1 = {style={data visualization/my plot style}}}, %internal
}

\begin{document}

\begin{tikzpicture}
    \datavisualization[
        school book axes,
        all axes = {grid = none},
        x axis = {label = $\Re$},
        y axis = {
            unit length = 2em,
            label = $\Im$
        },
        clean ticks,
        visualize as scatter = poles,
        visualize as circle = zeros,
        visualize as line/.list = {
            root locus 1,
            root locus 2,
            root locus 3,
            root locus 4,
            root locus 5,
            root locus 6
        },
        set style for plots={->,red}{
            root locus 1,
            root locus 2,
            root locus 3,
            root locus 4,
            root locus 5,
            root locus 6,
        },
    ]
    data[set = poles] {
                       x,     y
                       -5,     0
                       -3,     0
                       -3,    -1
                       -3,     1
                        0,     0
                         .05,  0
                      }
    data[set = zeros] {
                       x,     y, radius
                       -5.2,  0, 2pt
                       -3.2,  0, 2pt
                       -1,    0, 2pt
                       -1.05, 0, 2pt
                      }
    data[set = asymptotes] {
                            x,    y
                            -1.8, -5.5
                            -1.8,  5.5
                           }
    data[set=root locus 1] {
                            x,      y
                             0,     0
                             0,      .01
                             0,      .015
                             0,      .024
                             -.001,  .037
                             -.002,  .057
                             -.005,  .089
                             -.013,  .137
                             -.031,  .211
                             -.075,  .32
                             -.129,  .408
                             -.183,  .473
                             -.247,  .53
                             -.31,   .572
                             -.372,  .6
                             -.431,  .618
                             -.496,  .628
                             -.554,  .628
                             -.605,  .621
                             -.648,  .609
                             -.716,  .579
                             -.764,  .548
                             -.835,  .482
                             -.874,  .433
                             -.915,  .366
                             -.967,  .236
                             -.987,  .152
                             -.994,  .098
                             -.998,  .063
                             -.999,  .041
                            -1,      .026
                            -1,      .017
                            -1,      .011
                            -1,      .007
                            -1,      .005
                            -1,      .003
                            -1,      .002
                            -1,      .001
                            -1,     0
                           }
    data[set=root locus 2] {
                            x,      y
                             0,     0
                             0,     -.01
                             0,     -.015                                 
                             0,     -.024
                             -.001, -.037
                             -.002, -.057
                             -.005, -.089
                             -.013, -.137
                             -.031, -.211
                             -.075, -.32
                             -.129, -.408
                             -.183, -.473
                             -.247, -.53
                             -.31,  -.572
                             -.372, -.6
                             -.431, -.618
                             -.496, -.628
                             -.554, -.628
                             -.605, -.621
                             -.648, -.609
                             -.716, -.579
                             -.764, -.548
                             -.835, -.482
                             -.874, -.433
                             -.915, -.366
                             -.967, -.236
                             -.987, -.152
                             -.994, -.098
                             -.998, -.063
                             -.999, -.041
                            -1,     -.026
                            -1,     -.017
                            -1,     -.011
                            -1,     -.007
                            -1,     -.005
                            -1,     -.003
                            -1,     -.002
                            -1,     -.001
                            -1,     0}
    data[set=root locus 3] {
                            x,    y
                            -5,   0
                            -5.2, 0
                           }
    data[set=root locus 4] {
                            x,      y
                            -3,     1
                            -3,     1.001
                            -2.999, 1.001
                            -2.998, 1.003
                            -2.996, 1.007
                            -2.990, 1.017
                            -2.977, 1.04
                            -2.947, 1.095
                            -2.882, 1.22
                            -2.81,  1.36
                            -2.742, 1.493
                            -2.665, 1.645
                            -2.592, 1.793
                            -2.522, 1.939
                            -2.457, 2.083
                            -2.385, 2.256
                            -2.321, 2.427
                            -2.266, 2.595
                            -2.218, 2.76
                            -2.143, 3.076
                            -2.089, 3.373
                            -2.009, 4.009
                            -1.963, 4.563
                            -1.913, 5.509
                           }
    data[set=root locus 5] {
                            x,      y
                            -3,     -1
                            -3,     -1.001
                            -2.999, -1.001
                            -2.998, -1.003
                            -2.996, -1.007
                            -2.99,  -1.017
                            -2.977, -1.04
                            -2.947, -1.095
                            -2.882, -1.22
                            -2.81,  -1.36
                            -2.742, -1.493
                            -2.665, -1.645
                            -2.592, -1.793
                            -2.522, -1.939
                            -2.457, -2.083
                            -2.385, -2.256
                            -2.321, -2.427
                            -2.266, -2.595
                            -2.218, -2.76
                            -2.143, -3.076
                            -2.089, -3.373
                            -2.009, -4.009
                            -1.963, -4.563
                            -1.913, -5.509
                           }
    data[set=root locus 6] {
                            x,    y
                            -3,   0
                            -3.2, 0
                           };
\end{tikzpicture}

\end{document}

结果

在此处输入图片描述

相关内容