我的代码看起来像这样
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
中组合图形对象关于我如何处理这些问题的任何建议?
答案 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"}]]
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"}]
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"}]]