如何在mathematica中添加多个图的图例?

时间:2017-09-26 21:05:51

标签: plot label wolfram-mathematica legend

我的代码看起来像这样

    gx = n * k0 * (1 - ((n/a)^ beta)
    Show[
    Plot[gx /. {k0 -> 0.5, beta -> 5, n -> 9, a -> 1}, {n, 0, 12}, PlotRange -> {{0, 12}, {0, 5}}, PlotLabels -> {"r0 = 0.5"}],
    Plot[gx /. {k0 -> 0.5, beta -> 0.5, n -> 9, a -> 1}, {n, 0, 12}, PlotRange -> {{0, 12}, {0, 5}}, PlotLabels -> {"r0 = 0.8"}]
        ]

然而,我将标签一个放在另一个上面并且没有明显标记。

或者,我尝试过使用过的传说

Show[
Plot[gx /. {k0 -> 0.5, beta -> 5, n -> 9, a -> 1}, {n, 0, 12}, PlotRange -> {{0, 12}, {0, 5}}],
Plot[gx /. {k0 -> 0.5, beta -> 0.5, n -> 9, a -> 1}, {n, 0, 12}, PlotRange -> {{0, 12}, {0, 5}}],
PlotLegends -> {"beta = 5", "beta=0.5"}
    ]

我得到一个错误,表示无法在Show

中组合图形对象

关于我如何处理这些问题的任何建议?

1 个答案:

答案 0 :(得分:2)

此处显示了三种变体。

gx = n*k0*(1 - ((n/a)^beta));

Show[
 Plot[gx /. {k0 -> 0.5, beta -> 5, n -> 9, a -> 1}, {n, 0, 12},
  PlotRange -> {{0, 12}, Automatic}, PlotLabels -> {"beta = 5"}],
 Plot[gx /. {k0 -> 0.5, beta -> 0.5, n -> 9, a -> 1}, {n, 0, 12},
  PlotRange -> {{0, 12}, Automatic}, PlotLabels -> {"beta=0.5"}]]

enter image description here

Plot[
 {gx /. {k0 -> 0.5, beta -> 5, n -> 9, a -> 1},
  gx /. {k0 -> 0.5, beta -> 0.5, n -> 9, a -> 1}},
 {n, 0, 12}, PlotRange -> {{0, 12}, Automatic},
 PlotLegends -> {"beta = 5", "beta=0.5"}]

enter image description here

Legended[Show[
  Plot[gx /. {k0 -> 0.5, beta -> 5, n -> 9, a -> 1}, {n, 0, 12},
   PlotStyle -> ColorData[97][1], PlotRange -> {{0, 12}, Automatic}],
  Plot[gx /. {k0 -> 0.5, beta -> 0.5, n -> 9, a -> 1}, {n, 0, 12},
   PlotStyle -> ColorData[97][2], PlotRange -> {{0, 12}, Automatic}]],
 LineLegend[ColorData[97] /@ {1, 2}, {"beta = 5", "beta=0.5"}]]

enter image description here