将二维图形改进为三维曲线族

将二维图形改进为三维曲线族

我有一组/一组曲线的 (x,y) 坐标。每条曲线对应不同的 z 值,但曲线之间的 x 值或 y 值没有相关性。也就是说,我无法将曲线集表示为表格,它实际上是几个 x,y 对列表。

在此处输入图片描述

我想尝试将曲线做成 3d 形式,看看这样是否更易于阅读,以及是否可以从此消除对颜色编码的需求。我希望避免使用颜色编码,以更好地照顾色盲观众,同时实现黑白打印。

下面是 latex 代码。有人能建议一种将其转换为 3d 图像的方法吗?我是否需要重新开始并使用完全不同的包,或者我是否可以通过一些调整仍然使用 tikzpicture 和朋友来做到这一点?

欢迎提出建议。

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
 xlabel=BDD Size,
 ymajorgrids,
 yminorgrids,
 xmajorgrids,
 xminorgrids,
 ylabel=Probability,
legend style={font=\tiny},
 label style={font=\tiny}
]
\addplot+[] coordinates {
  (1,0.125)
  (3,0.25)
  (4,0.5)
  (5,0.125)
};
\addplot+[] coordinates {
  (1,0.0078125)
  (3,0.0234375)
  (4,0.09375)
  (5,0.2421875)
  (6,0.34375)
  (7,0.2890625)
};
\addplot+[] coordinates {
  (1,0.001998002)
  (3,9.99001e-4)
  (5,0.003996004)
  (6,0.00999001)
  (7,0.062937066)
  (8,0.14985014)
  (9,0.25174826)
  (10,0.36963037)
  (11,0.14885116)
};
\addplot+[] coordinates {
  (1,0.001998002)
  (7,9.99001e-4)
  (9,9.99001e-4)
  (11,0.003996004)
  (12,0.018981019)
  (13,0.05894106)
  (14,0.14085914)
  (15,0.22077923)
  (16,0.3126873)
  (17,0.17782217)
  (18,0.05894106)
  (19,0.002997003)
};
\addplot+[] coordinates {
  (1,0.001998002)
  (8,9.99001e-4)
  (18,9.99001e-4)
  (20,9.99001e-4)
  (21,0.003996004)
  (22,0.017982017)
  (23,0.04995005)
  (24,0.0989011)
  (25,0.17682318)
  (26,0.22977023)
  (27,0.21278721)
  (28,0.15484515)
  (29,0.03996004)
  (30,0.008991009)
  (31,9.99001e-4)
};
\addplot+[] coordinates {
  (1,0.001998002)
  (9,9.99001e-4)
  (38,0.003996004)
  (39,0.006993007)
  (40,0.022977022)
  (41,0.050949052)
  (42,0.1058941)
  (43,0.17582418)
  (44,0.21578422)
  (45,0.21778221)
  (46,0.15084915)
  (47,0.045954045)
};
\addplot+[] coordinates {
  (1,0.001998002)
  (10,9.99001e-4)
  (67,9.99001e-4)
  (69,9.99001e-4)
  (70,0.014985015)
  (71,0.021978023)
  (72,0.064935066)
  (73,0.10489511)
  (74,0.16483517)
  (75,0.21378621)
  (76,0.2007992)
  (77,0.13286713)
  (78,0.064935066)
  (79,0.010989011)
};
\legend{"Size with 2 variables","Size with 3 variables","Size with 4 variables","Size with 5 variables","Size with 6 variables","Size with 7 variables","Size with 8 variables"}
\end{axis}
\end{tikzpicture}

\end{figure}
\end{document}

答案1

我会采取不同的策略。我会坚持使用 2D 打印页面,但我会利用可编程绘图工具的强大功能“手工”绘制图表,而不是尝试让绘图包自动完成您所需的所有工作。

在这里我用的是元帖子包装在luamplib(因此您需要使用编译lualatex或改编它以适应 Plain MP 或gmp包)。其他人可以向您展示如何使用 TikZ 做类似的事情。

我编写了一个自定义addplot例程来绘制每条曲线。我利用语言的可编程功能来更改每条线的虚线图案,并在需要的地方添加标签,而不是使用笨重的图例。

在此处输入图片描述

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

vardef addplot(expr first)(text list_of_pairs) = 
    path p_; pair maximum; maximum := first; 
    p_ := (first for $=list_of_pairs: -- $ 
        hide(if ypart $ > ypart maximum: maximum := $; fi)
    endfor) xscaled u yscaled v;
    draw p_ dashed evenly scaled (2/n);
    for t=0 upto length p_: fill fullcircle scaled 2 shifted point t of p_; endfor
    if n=3: 
       draw hide(maximum := maximum shifted (0.1,0.01)) maximum xscaled u yscaled v -- 
            hide(maximum := maximum shifted (  1,0.08)) maximum xscaled u yscaled v 
            withpen pencircle scaled 1/4; 
    fi
    label.urt("$n=" & decimal n & "$", maximum xscaled u yscaled v);
enddef;

beginfig(1);

    numeric n, u, v;
    u = 120mm/80; v = 80mm; 

    path xx, yy;
    xx = (origin -- right) scaled 85u shifted 10 down;
    yy = (origin -- up) scaled .6 v shifted 10 left; 

    drawoptions(withcolor 1/4 white);
    drawarrow xx;  label("BDD Size", point 1/2 of xx shifted 20 down);
    drawarrow yy;  label("Probability", point 1 of yy shifted 10 up);
    for i=0 step 20 until 80: label.bot(decimal i, (i*u,-10)); endfor
    for i=0 step 1 until 5: label.lft(decimal (i/10), (-10,i*v/10)); endfor
    drawoptions();

    label("BDD size with $n$ variables", (60u, 0.5v));

    n := 2;
    addplot(
      (1,0.125),
      (3,0.25),
      (4,0.5),
      (5,0.125));
    n := 3;
    addplot(
      (1,0.0078125),
      (3,0.0234375),
      (4,0.09375),
      (5,0.2421875),
      (6,0.34375),
      (7,0.2890625));
    n := 4;
    addplot(
      (1,0.001998002),
      (3,0.000999001),
      (5,0.003996004),
      (6,0.00999001),
      (7,0.062937066),
      (8,0.14985014),
      (9,0.25174826),
      (10,0.36963037),
      (11,0.14885116));
    n := 5;
    addplot(
      (1,0.001998002),
      (7,0.000999001),
      (9,0.000999001),
      (11,0.003996004),
      (12,0.018981019),
      (13,0.05894106),
      (14,0.14085914),
      (15,0.22077923),
      (16,0.3126873),
      (17,0.17782217),
      (18,0.05894106),
      (19,0.002997003));
    n := 6;
    addplot(
      (1,0.001998002),
      (8,0.000999001),
      (18,0.000999001),
      (20,0.000999001),
      (21,0.003996004),
      (22,0.017982017),
      (23,0.04995005),
      (24,0.0989011),
      (25,0.17682318),
      (26,0.22977023),
      (27,0.21278721),
      (28,0.15484515),
      (29,0.03996004),
      (30,0.008991009),
      (31,0.000999001));
    n := 7;
    addplot(
      (1,0.001998002),
      (9,0.000999001),
      (38,0.003996004),
      (39,0.006993007),
      (40,0.022977022),
      (41,0.050949052),
      (42,0.1058941),
      (43,0.17582418),
      (44,0.21578422),
      (45,0.21778221),
      (46,0.15084915),
      (47,0.045954045));
    n := 8;
    addplot(
      (1,0.001998002),
      (10,0.000999001),
      (67,0.000999001),
      (69,0.000999001),
      (70,0.014985015),
      (71,0.021978023),
      (72,0.064935066),
      (73,0.10489511),
      (74,0.16483517),
      (75,0.21378621),
      (76,0.2007992),
      (77,0.13286713),
      (78,0.064935066),
      (79,0.010989011));

endfig;
\end{mplibcode}
\end{document}

相关内容